Thursday, August 12, 2010


Courtesy of SCJP Sun® Certified Programmer for Java™ 6 Study Guide Exam (310-065) (9780071591065)
Chapter 6, Question 8

The output of this program is 

10 0 10

Before the values were written out, z was 9. Afterwards, it was incremented. Please remember that z is a static variable, meaning it belongs to the class definition, hence it doesn't get serialized. 

In order to alter standard deserialization process, implement the readObject() method in SpecialSerial. This readObject() will call defaultReadObject().

Please see below code

Compile and run this code. Output will be:

10 7 10

No comments:

Post a Comment