Ratan Kumar Ratan Kumar - 1 year ago 85
Java Question

What is the difference between an Object , Reference ID , and Reference Variable in Java?

What is difference between the following in java :

  1. Object

  2. Reference ID

  3. Reference Variable

When I see statements like this:

Emp e = new Emp();

is class, but
is not its object? If that is so .. somewhere else I have seen this:

cos if it is so then ..somewhere is see like

Emp e = new Local();

Where local is a child class of
. So what does
mean in this case? What does it hold?

Answer Source

An object is, essentially, a chunk of memory living in the heap. (Part of the memory structure of objects includes a reference to the class of that object.)

Object variables in Java (like e, in this example) contain references to objects living in the heap.

Classes are completely different from all of these; they might describe the structure of objects of that type, and have method implementations and the like, but classes live in an entirely different area of memory from other objects.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download