Java – How are constructors called during serialization and deserialization

javaserialization

How are the constructors called during serialization and deserialization

  1. When there is one class implementing serializable?
  2. When there is parent/child relationship and only child implements serializable?
  3. When there is parent/child relationship and both parent and child implements serializable?

Best Answer

During deserialization the accessible default constructor is called for the first class in the inheritance hierarchy that does not implement Serializable.

> A Serializable class must have access to the no-arg constructor of its first nonserializable superclass