What will happen to classCounter Variable?
If I serialize this object and then again deserialize and get object what will be value of classCounter
?
I created 5 object classCounter = 5
what I will get in new object ?
Public Counter implements se开发者_如何学编程rializable {
private static classCounter = 0;
Counter (){
classCounter ++;
}
}
Well it will not affect the counter at all. More over if you transfer serialized data to jvm with different classloader it may occur that counter is less then 5.
Default constructor is not called for Serializable classes on deserialization, so classCounter++
is not called.
But you have to know, that default constructor will be called for superclasses if they don't implement Serializable. See explanation here.
精彩评论