Object Reference Variable in Java | Java Training
This Java Training”Object Reference Variable in Java” post explains clearly what is Object reference variable and how constructor returns reference of Object and much more.
How to access non-static members from non static context?
Using ‘this’ keyword.
How to access non-static members from static context?
Using “Object reference variable.
What is Object Reference Variable?
- It is a variable of Class type.
- It holds Object address.
- Constructor doesn’t have any return type in it’s definition
- Constructor implicitly returns address of Object after its creation.
- We must collect address into “class type variable”
- Class is called User defined data type.
Program that Print Object address using Object reference variable in Static context:
System.out.println("Object address inside constructor : "+this);
public static void main(String args[ ])
Test obj = new Test();
System.out.println("Object address inside main : "+obj);