Given the following code what will be the output?class ValHold{
public int i = 10;
}public class ObParm{
public static void main(String argv[]){
ObParm o = new ObParm();
o.amethod();
}
public void amethod(){
int i = 99;
ValHold v = new ValHold();
v.i=30;
another(v,i);
System.out.print( v.i );
}//End of amethod public void another(ValHold v, int i){
i=0;
v.i = 20;
ValHold vh = new ValHold();
v = vh;
System.out.print(v.i);
System.out.print(i);
}//End of another}
1) 10030
2) 20030
3) 209930
4) 10020我一开始觉得是10010,又一想应该是10020,请帮分析下
public int i = 10;
}public class ObParm{
public static void main(String argv[]){
ObParm o = new ObParm();
o.amethod();
}
public void amethod(){
int i = 99;
ValHold v = new ValHold();
v.i=30;
another(v,i);
System.out.print( v.i );
}//End of amethod public void another(ValHold v, int i){
i=0;
v.i = 20;
ValHold vh = new ValHold();
v = vh;
System.out.print(v.i);
System.out.print(i);
}//End of another}
1) 10030
2) 20030
3) 209930
4) 10020我一开始觉得是10010,又一想应该是10020,请帮分析下
http://blog.sina.com.cn/s/blog_70677d110100mszj.html
v = vh;把v已经改变了,v.i不再是30了