When is memory allocated for a static variable in java?

All class objects share a static variable. But when is memory allocated for a static variable? Is this when the first object is created for the class? Or does this happen even before any instance of the class is created? Also, an instance variable is allocated memory at runtime. Is memory for a static variable allocated at runtime or compile time?

+6
source share
2 answers

When the class is loading at runtime. You can find the details here.

+3
source

when the class loader loads the class, a memeory will be allocated for all static variables, and this will be done only once

0
source

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


All Articles