Where are instance variables of an Object stored in the JVM?

后端 未结 3 1427
礼貌的吻别
礼貌的吻别 2020-12-13 15:53

Is an instance variable of an object in Java stored on the stack or method area of the JVM?

Also, do we have different instance variable for multiple threads?

3条回答
  •  庸人自扰
    2020-12-13 16:08

    To be precise,

    • Instance variables will be stored on the heap.
    • local variables on the stack(in case of variable not a primitive[reference variable] reference variables live on stack
      and the object on heap ). Only method invocation and partial results will be stored in stack not the method itself.
    • Static variables and Methods(including static and Non Static) on the Method Area.

    Reference: Head First Java

提交回复
热议问题