class s{
int i;
String st;
}
class shi {
public static void main(String[]args){
s x=new s();
s y=new s();
x.i=34;
y.i=2;
x.st=new String("well");
y.st=new String("hello");
y=x;
System.out.println(x.i+" "+y.i+x.st+" "+y.st);
}
}
上面的"y=x"明明是引用传值,而st本身也是个引用,当x的st传给y的st时,x.st应该被改写为"hello"的啊,可是事实上x.st和y.st都是"well",怎么回事呢?
int i;
String st;
}
class shi {
public static void main(String[]args){
s x=new s();
s y=new s();
x.i=34;
y.i=2;
x.st=new String("well");
y.st=new String("hello");
y=x;
System.out.println(x.i+" "+y.i+x.st+" "+y.st);
}
}
上面的"y=x"明明是引用传值,而st本身也是个引用,当x的st传给y的st时,x.st应该被改写为"hello"的啊,可是事实上x.st和y.st都是"well",怎么回事呢?
当x的st传给y的st时,x.st应该被改写为"hello"的啊
-----------------------------------------------
??????
当x的st传给y的st时,y.st应该被改写为"well"的引用