What is difference between the following in java :
Object
Reference ID
Reference Variable
When I see statements like this:
Emp e = new Emp();
Here Emp is class, but e 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 Emp. So what does e mean in this case? What does it hold?
解决方案
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.