-
实例变量 属于实例,存在
堆
内存里,和对象同生命周期。 局部变量 属于方法,存在栈
内存里,和方法同声明周期。
1)Local variables
are stored on the stack.Instance and static variables
are stored on the heap.
2)Don’t forget that forreference type variables
, the value of a variable ris a eference, not the object.
(Arrays are reference types too - so if you have an int[], the values will be on the heap.)
-----------------------------------------------------------------------------摘自 Where does the JVM store primitive variables?. -
成员变量 修饰符
没限制
(public
、protected
、默认
、private
、static
、final
) ; 局部变量 只可以被final
修饰。 -
成员变量 有默认值 ; 局部变量 无默认值。
成员变量与局部变量的区别?
于 2021-08-28 18:21:31 首次发布