This is fine as Animal class didn't implement Serializable interface so weight got its intialized value of 42. My question is if I modify Animal class as -
The output is before: Fido 35 after: Fido 0
Can somebody please explain why in this case I am getting 0 for weight instead of 42?
Joined: Apr 20, 2008
if you do not use serialization on parent class, it's attribute will not be serialized no matter you mark it as transient or not. When you deserialized, the attribute from not serialized parent class will be initialized. But on serialized parent class, a transient attribute is not serialized or deserialized, so the value is 0 as in default value