Since the superclass does not implement the serializable contents of the superclass, it will not be serialized. Only the contents of the subclass would receive serialization. When you do the deserialization, the default constructor of the superclass will be executed, and the fields of the superclass will be initialized as if you were calling the default constructor.
The following example illustrates this.
public class SerializationTest { public static class Base { private String name; public Base() { this.name = "johnDow"; } public String getName() { return name; } public void setName(String name) { this.name = name; } } public static class Sub extends Base implements Serializable { private static final long serialVersionUID = 1L; private String age; public String getAge() { return age; } public void setAge(String age) { this.age = age; } } public static void main(String[] args) throws Exception { ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(byteArrayOS); Sub s = new Sub(); s.setName("name"); s.setAge("10"); out.writeObject(s); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(byteArrayOS.toByteArray())); Sub d = (Sub) ois.readObject(); System.out.println(d.getName() + "-" + d.getAge()); } }
What is printed
johnDow-10
source share