How are static arrays stored in Java memory?

前端 未结 7 1957
名媛妹妹
名媛妹妹 2021-02-18 21:33

So in a language like C, memory is separated into 5 different parts: OS Kernel, text segment, static memory, dynamic memory, and the stack. Something like this:

7条回答
  •  遇见更好的自我
    2021-02-18 22:13

    In Java, a static variable exists as part of the class object. Think of it as an instance variable for the class itself. In your example, a is a reference variable, which refers to some array (or no array at all, if it is null), but the array itself is allocated as all arrays are in Java: off the heap.

提交回复
热议问题