posted 13 years ago
Hi,
In line 15, when we do a new CardPlayer(), since CardPlayer extends Player, first Player's constructor and then CardPlayer's constructors will be invoked. Making the output "pc". This is irrespective of whether serialization is in picture or not.
Now, coming to the question, the statement posted itself explains the output. CardPlayer implements Serializable but not Player class.
So, when the serialized object c1 is read back/deserialized, it realizes that its parent Player does not implement Serializable. Hence, Player's constructor will be run. So, the additional "p" at the end making the output "pcp". And, yes, as you have mentioned constructors will not run during deserialization for classes that implement serializable. Hence, constructor of CardPlayer is not invoked while deserializing c1. Hope this clarifies your question.
Lokesh
( SCBCD 5, CCENT, SCJP 5 )