Forums Register Login

instantiation

+Pie Number of slices to send: Send
Hi,

When you instantiate an object, Mammal human = new Mammal(), the address or reference of the object is stored somewhere in memory which we refer to as human. I don't know how this whole thing works, please someone explain to me in a simple way. So human refers to a block of memory,which contains an address leading to another block of memory which is storing the object???
Thanks
+Pie Number of slices to send: Send
All you need to know is that human keeps something like a 'pointer' (reference) to the object instance which is somewhere on the heap.
+Pie Number of slices to send: Send
Basically, The Java Virtual Machine Specification says that a "variable is a storage location," and a "variable of reference type can hold ... a reference to any object whose class is assignment compatible (ยง2.6.7) with the type of the variable." Ultimately, these "reference values ... are pointers to these objects." (See 2.4.6 Reference Types, Objects, and Reference Values and 2.5 Variables.)

I think the level of detail you're asking about might be specific to the implementation of the JVM. I don't think we can know whether a Java reference points directly to the object itself, or whether it points to some sort of "table" that stores an address of the object.
You get good luck from rubbing the belly of a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 705 times.
Similar Threads
instantiation again
secure application (memory encription)
References and Class Hierarchies
garbage collection assigning null value
Grammar question relating to Constructor
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 09:07:58.