| Author |
reference or value about Java
|
Chen SanHau
Greenhorn
Joined: Feb 06, 2004
Posts: 27
|
|
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
Joined: Jul 08, 2003
Posts: 24061
|
|
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.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Chen SanHau
Greenhorn
Joined: Feb 06, 2004
Posts: 27
|
|
|
Thank your help !!!
|
 |
 |
|
|
subject: reference or value about Java
|
|
|