+ 1
What is the difference between an object and an object reference in java?
3 Respuestas
+ 17
● A reference variable points to an actual object , here is nice explantion on it : http://www.hacktrix.com/difference-between-object-and-reference-in-java
+ 10
https://code.sololearn.com/cqa0MSc4pvDb/?ref=app
+ 2
An object is an runtime instance of a class in memory(i.e. RAM)
A reference is nothing but a variable that stores the memory address of the object
Consider the following example:
MyClass ref = new MyClass();
In the above statement, the RHS i.e. new MyClass() creates an object and return it's memory; and the reference variable ref stores that address.
You can check what address the reference variable ref stores by the statement System.out.print(ref)