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",怎么回事呢?

解决方案 »

  1.   

    很久就想研究一下java的内存运作,我也感觉到学java没有了解内存运作,写代码时老是错。哪里能了解到这方面的知识?
      

  2.   

    -----------------------------------------------
    当x的st传给y的st时,x.st应该被改写为"hello"的啊
    -----------------------------------------------
    ??????
    当x的st传给y的st时,y.st应该被改写为"well"的引用