Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is "reference of any object" and "object"

 
Tomendra Singh
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi people,
i am confuse in that what is "reference of any object" and "object".
actually i know what is object but i am confuse in that what is "reference of an object."
please provide any simplest example with some code so that i can understand better.

thank you.
 
Larry Frissell
Ranch Hand
Posts: 82
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In another thread Fred Rosenberger stated it best
personally, i think of references as notecards with address on them, and they refer to a house.

when you 'pass an object' into a method, you are really passing a copy of the reference. So, you are effectively passing a copy of the address.


So an object is a house, the reference is the address of where the house is located.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12185
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when you say

MyObject foo = new MyObject();

two things are created. an object is made on the heap somewhere. you don't have direct access to this. this is the house.

a reference called "foo" is made. this is the notecard, which you DO have. the '=' then writes the address on the card.

so in this case, there is an object somewhere. 'foo' is the reference to the object - it's how you get to the object.
 
Tomendra Singh
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Larry, but please can you or anyone tell me it with some java example. please put very simple examples.
 
Tomendra Singh
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot fred,thank you very very much. now i have understood.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic