Where java static variables are stored in memory?
26,042
First, static member variables are stored in the Permanent Generation area of heap.
Your example contains primitive type variables, they will be stored in the PermGen.
If those were object type variables, e.g. static Object x = new Object();
, then the reference x
would be stored in PermGen whereas the Object
itself would be placed in Young Generation of the heap.
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Author by
Admin
Updated on July 19, 2022Comments
-
Admin almost 2 years
class A{ static int i = 10; static int j = 20; static void getname(){ } }
Where will these variable be stored in memory ?