Why I don't have there NotSerializableException
cause in class A
that is serialized I have private B b
that is not serialized and I know that if class implement Serializable
all composite classes have to implement Serializable
/Externalizable
as well.
import java.io.*;
public class Test
{
public static void main(String[] args) throws IOException
{
FileOutputStream fileOutput = new FileOutputStream("a.dat");
ObjectOutputStream outputStream = new ObjectOutputStream(fileOutput);
outputStream.writeObject(new A());
fileOutput.close();
outputStream.close();
}
}
class A implements Serializable
{
private int age;
private B b;
}
class B
{
}