[Java] About static

less than 1 minute read

After loading, the class file is separated into the static part and the other parts, and each is saved in a different memory area.
static.png

Members qualified with static are placed in the static area, and other definitions are placed in the metaspace area (native memory).

–When an instance is created, ** the instance area is secured in the heap area according to the class definition in the metaspace area **
-** Static fields can be used without instantiation **
–Write “class name.field name” to access static fields. Or create an instance and access it using that reference.
–Static members can be used without an instance, while non-static members cannot be used without an instance. Therefore, ** static methods cannot access non-static members **
–Conversely, it is possible to access static members from non-static methods

References

Thorough capture Java SE11 Silver problem collection

Tags:

Updated: