Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are constructors called during serialization and deserialization?

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?
like image 702
Rekha Avatar asked Nov 15 '11 18:11

Rekha


People also ask

Is constructor called during deserialization?

The deserialization process does not use the object's constructor - the object is instantiated without a constructor and initialized using the serialized instance data.

What is valid about constructor call during deserialization process in?

What Is valid about constructor call during DeSerialization process in java? b. if Externalizable has been implemented - constructor is called during DeSerialization process.

Is constructor of super class called during deserialization process of subclass in Java?

JavaMadeSoEasy.com (JMSE) If Serializable has been implemented - constructor is not called during DeSerialization process. But, if Externalizable has been implemented - constructor is called during DeSerialization process.

How is the constructor called or invoked?

The constructor in C++ has the same name as the class or structure. Constructor is invoked at the time of object creation. It constructs the values i.e. provides data for the object which is why it is known as constructors. Constructor does not have a return value, hence they do not have a return type.


1 Answers

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

like image 167
szhem Avatar answered Oct 02 '22 02:10

szhem