How does the JVM handle a static variable?

class A{
  static int a=5;
  int b=6;

  void method(){
    //method body
     a++;
  }
}

How the JVM processes a static variable, processes a static variable. eg...

A object1=new A();
A object2=new A();

Above the code will create two objects of class A in two different memory cells. Two instances will also be created variable b. What will happen for variable a. which object will contain the link for the static variable? and what happens when we update a static variable?

+1
source share
4 answers

", in which the object will contain a link for a static variable

, - , . , ( ), " ".

https://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html

+3

a, a.

- - . () , a, .

. Oracle Java Tutorials:

+1

, A .

: ( ) , , , .

+1

" , ( ), , ( - ), "

bcz -

A object1 = new A(); a = 5 b = 6

A object2 = new A(); a = 5 b = 6

object1.method(); a = 6 b = 6

object2.method(); a = 7 b = 6

0
source

Source: https://habr.com/ru/post/1606098/


All Articles