Hi there! I wonder what exactly happens to a static variable that has been declared and initialized in a class that implements Serializable and when that class is passed to an output stream with the writeObject() method as follows:
Output: 10 0 10
As static variables would not be serialized, should'nt s2.z return 0? What exactly is happening here. Can someone explain?
Life is like a day. If the day is of no use, neither a month or a year.
Joined: Feb 02, 2006
Run B.class after runing A.class. You will get s2.z=9. because z is static member and will initialized when the class is loaded (first time).
Joined: Oct 02, 2006
don't get confused by transient. after being deserialized, transient variable is reset to its default value, while static variable keeps its original value