Praveen Kumar M K wrote:Dear Ranchers,
Consider a sample class called Employee and following declaration of a Employee variable,
Here's my understanding about this statement,
There are say 2000 houses(or memory blocks) within the runtime memory which can house 2000 instances of "Object"s. One such house, say No.42 contains the newly created Employee object, which can be housed because it is a subinstance of Object.
And what "emp" contains is this value 42, which on further re-direction fetches the actually object.
What emp contains is not defined by the spec. It is implementation specific. In an abstract sense, it is the "address of the object", but that doesn't mean it's literally the memory address where the first member variable is. In one version, then value was a pointer to a pair of pointers, where one of that pair pointed to the class definition and the other to the object's data. In a later version, I think it was a pointer to a structure that contained a pointer to the class definition, followed by the object's member data. Note also that there's almost certain a least one more layer of indirection in there, so that objects can be moved around by the JVM and pages shuffled around by the OS without application pointers having to change.
What kind of variable is this reference "emp"?Is there a special type say MemType, which is defined to be always a number which can range from 1 - 2000(just saying, in this case).
It's entirely up to the JVM implementation.
If there is indeed something like a Memtype, is there any inheritance/association between a super MemType and a sub Employee type.
No. The type as far as the
Java language is concerned is simply "reference". If there is a MemType, it exists only in the language and context in which the JVM is written. Whatever type the implementation is, that is not visible to our Java code.