If I create a static block and create an object there, say about some other class, will the object be created on the heap or on the stack?
class Hello { static { Abc abcObject=new Abc(); } // Other Code... }
An object is created on the heap, but an object reference is on the stack.
The variable abcObjectyou created is on the stack. This contains the memory address on the heap where the object is stored new Abc().
abcObject
new Abc()
Objects are always on the heap regardless of static (or) non-static.
Links will be on the stack.