*
The moose likes Beginning Java and the fly likes reference or value about Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "reference or value about Java" Watch "reference or value about Java" New topic
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: 24183
    
  34

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 !!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: reference or value about Java
 
Similar Threads
java about pass by value,why?
strange behaviour of reference variable when passing to a function
code not understood
What will be the output??? Help me please
Reference passing