Originally posted by chao-long liao:
public class A {
static String sName = "a";
public static void main(String argv[]){
A t = new A();
t.piggy(sName);
System.out.println(sName);
}
public void piggy(String sName){
sName = sName + "b";
}
}
My answer is "ab",but the output is "a",why??
Guoqiao Sun<br />SCJP2 SCWCD2<br />Creator of <a href="http://www.jiris.com/" target="_blank" rel="nofollow">www.jiris.com</a>, Java resource, mock exam, forum
Originally posted by chao-long liao:
Thanks everybody ^_^
But I still have a question,in Java,
there are two ways to pass argument.
1. pass by value
//used by primitive data,it dosen't change the original value
2. pass by reference
//used by reference,it will change the original value
the above statement is correct??
this question is a reference,why using "pass by value"??
Originally posted by chao-long liao:
Thanks everybody ^_^
But I still have a question,in Java,
there are two ways to pass argument.
1. pass by value
//used by primitive data,it dosen't change the original value
2. pass by reference
//used by reference,it will change the original value
the above statement is correct??
this question is a reference,why using "pass by value"??
Ashik Uzzaman
Engineering Manager, Marqeta, Oakland, CA, USA
Don't get me started about those stupid light bulbs. |