• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

instantiation

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All you need to know is that human keeps something like a 'pointer' (reference) to the object instance which is somewhere on the heap.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic