Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reference or value about Java

 
Chen SanHau
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know how to give the subject of my question. I'm a new learner about Java. I would be very appreciated of your help !!


Line 12 is my question?
I hope your help!!!
Thanx!!
[ February 06, 2004: Message edited by: Ha LoHa ]
[ February 06, 2004: Message edited by: Ha LoHa ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A variable is a reference to an object; it's not the object itself. If you assign a variable to point to a new object, then any old object it pointed to is still there, and any other variables that pointed to it still point to it.
So in "first" you pass a reference to a Value object to the method "second". "second" sets the member "i" of that Value object to 20, then makes the reference point to another Value object and manipulates this different object. "first" still holds a reference to the original Value, the one with 20 in its "i" member.
See the JavaRanch "Campfire Stories" for more information; in particular, take a few minutes to read this one.
 
Chen SanHau
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank your help !!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic