Instantiating a reference typesuggest change
Object obj = new Object(); // Note the 'new' keyword
Objectis a reference type.
objis the variable in which to store the new reference.
Object()is the call to a constructor of
- Space in memory is allocated for the object.
- The constructor
Object()is called to initialize that memory space.
- The memory address is stored in
obj, so that it references the newly created object.
This is different from primitives:
int i = 10;
Where the actual value
10 is stored in
Table Of Contents