What is the actual memory place for static variables?

We have 3 segments in our memory:

  1. Stack Segment — contains local variables and Reference variables (variables that hold the address of an object in the heap).

  2. Heap Segment — contains all created objects in runtime, objects only plus their object attributes (instance variables).

  3. Code Segment — the segment where the actual compiled Java bytecodes resides when loaded.
    Static members (variables or methods) are called class members, meaning they reside where the class (bytecode) resides, which is in the Code Segment.

Leave a Comment