Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where in memory are objects located when they are created within a static block?

If I create a static block and create an Object there, say of some other class, will the object be created on the heap or on the stack?

class Hello {
   static {
       Abc abcObject=new Abc();
   }
   // Other Code...
} 
like image 873
Kumar Ritesh Avatar asked Sep 04 '12 15:09

Kumar Ritesh


1 Answers

Objects are always on heap irrespective of static (or) non-static .

References will be on stack.

like image 172
kosa Avatar answered Sep 18 '22 23:09

kosa