After deserialization if i want to retain the value of Static Fields, what should we do?
class Child
{
int x = 5; //Here is a instance variable we will try to get
static int y = 10; //A static variable that will be accessible to everyone
public static void main (String args[]) {
Child.testMeMethod();
}
static void testMeMethod(){
class test {
void methodTest(){
Child a = new Child();
System.out.println(a.x);// This works because you created an instance
System.out.println(Child.y);// This works because the variable is static
System.out.println(this.x); // This does not work because this method is static
// and won't have access to the "this object"
}
}
test t = new test();
t.methodTest();
}
}