Since those variables are defined as static, it doesn't matter what the instance is
Yes thats the whole point, Serialization is saving an objects state and not a class's state. When you have static variables they are part of the class and not any particular instance. Serialization applies only to objects.
After de-serialization the name being obj is just shadowing.
The var name obj is the same name but it is not shadowing. The object is deserialized and casted to DemoSerial.
The last line clearly states "Static variables are NEVER SAVED as part of object state...because they do not belong to the object". Then why is 7 saved in this case
Yes Static variables are NEVER SAVED as part of object state. 7 is saved because you changed the static variable value using an instance of another object (obj2) and you are trying to save the object referred by obj.
Hope this below code helps
but if you change int i from static to non-static
[ May 09, 2008: Message edited by: sridhar row ]