Junior — Middle
In which memory section are variables stored when declared as static?
sobes.tech AI
Answer from AI
Variables declared as static are stored in an area of memory called Metaspace in modern versions of the JVM (starting from Java 8). Previously, this was the PermGen (Permanent Generation) area. Metaspace stores class metadata, including static fields.
Thus, static variables belong to the class rather than an instance, and are stored in the memory area allocated for class metadata, not in the heap or stack.