A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Programmer Certification (SCJP/OCPJP)
pass by reference???
Joined: Mar 05, 2005
Mar 10, 2005 10:46:00
We say that in Java language we pass by value only, look into the snippet below:
public class PassByRef
public void change(PassByRef obj)
public static void main(
PassByRef obj1= new PassByRef();
System.out.println("*****obj1.i is **"+obj1.i);
System.out.println("*****obj1.j is **"+obj1.j);
Here we are passing the reference of the object as arguments to the method when method is called.
Thanks & Regards,
Joined: Jul 30, 2003
Mar 10, 2005 10:50:00
I don't see a question here. Are you asking something, or simply making an observation?
Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
Joined: Mar 13, 2004
Mar 10, 2005 11:25:00
method change() can alter the state of the object currently referred to by local variable obj1 but change() cannot alter obj1 to refer to a different object. What is being passed by value is not an object but a reference variable.
SCJP 1.4, SCWCD in process
Joined: Oct 12, 2000
Mar 10, 2005 11:52:00
In other words, the reference is passed by value.
Joined: Sep 24, 2003
Mar 10, 2005 16:26:00
See if this helps:
Java Q&A (FAQ, Trivia)
I agree. Here's the link:
subject: pass by reference???
Green mock 2, #51
object is assigned to null but not reflecting
passing parameters to a method.
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014