

A constructor resembles an instance method in java but it’s not a method as it doesn’t have a return type.
#JAVA CONSTRUCTOR NOT CALLED IN MAIN CLASS CODE#
Why default constructor is not called during deserialization process in java? Think in this way, what is the need of constructor?Ĭonstructor initializes the object variables with either default values or values which is assigned inside constructor. Constructor is a block of code that initializes the newly created object. You don't call the constructor manually instead, you create a new object and it's called automatically. How are Constructors invoked during Serialization and Deserialization process in Java. The class mpgCalculator only has the default constructor since you didn't define one. Before looking into this post, I recommend to first look at below post to understand how Serialization and Deserialization works in Java.
