class A{
static int a=5;
int b=6;
void method(){
//method body
a++;
}
}
How JVM handles static variable handles static variable. for example...
A object1=new A();
A object2=new A();
Above code will create two objects of class A in two different memory location. Also two instance of variable b will be created. What will happen for variable a. which object will hold the reference for the static variable? and what happen when we update static variable?
解决方案
"which object will hold the reference for the static variable"
Objects don't hold static variables as they are not bound to any object, they are bound to class.
Classes and all of the data applying to classes (not instance data) is stored in the Permanent Generation section of the heap.