java - How Deserialization works? - Stack Overflow
What is Deserialize & Serialize?
Java serialization/deserialization?
Explain like i'm five - what is Serializable?
Videos
You can take a look at ObjectInputStream source code. It uses reflection, it creates an object, reads fields from stream, and sets object's fields using reflection. You can run your code in a debugger and go step by step exactly to the line where age is set.
Now the the non serializable super class having no-arg constructor is Object.
Correct.
So basically SerializeDemo constructor is not called.
Correct.
Now when the Object is created during deserialization it will try to rebuild the instance state. So it will set age to 18.
Correct.
Question is how?
Reflection ... with access checks turned off.
The class descriptor in the serialized class gives the name and type of all of the serialized fields. The Class object defines Field objects for the actual class. The deserialization code matches the available serialized fields to the Field objects, and then uses Field.set(...) methods to set the field values.
(In fact, this is an implementation detail, but that's my understanding of how it works in current generation JVMs. You can always check the source code ...)