Objects lifecycle in memory
Box smallBox;
Unlike C++, the above statement won’t create an object. It will just create a reference variable. The reference variable has to be given an object.
Box smallBox= new Box();
Now smallBox
contains address of an object of Box class. That is, it points to the object. However, the object itself has no name.
- Memory is allocated on the Heap Space and a reference for that object is returned which is stored in Stack.
Children