When is the memory allocated for a static variable in java?
All the objects of a class share the static variable. But when is the memory allocated for the static variable? Is it when the first object is created for the class? Or does it happen even before any instance for the class is created? Also instance variable is allocated memory at runtime. The memory for static variable is allocated at runtime or compile time?
When the class is loaded, at runtime. You can find the details here.
当类加载器加载类时,所有静态变量的memeory将被分配,并且只会完成一次
链接地址: http://www.djcxy.com/p/82876.html上一篇: 堆谜语中的一个对象
下一篇: 什么时候在java中为静态变量分配内存?