publicclasspassingDemo{publicvoidfist(){xObjecto=newxObject();o.x=5;intx=5;changeThem(x,o);System.out.println();System.out.println("Backintheoriginalmethod");System.out.p...
public class passingDemo{
public void fist(){
xObject o=new xObject();
o.x=5;
int x=5;
changeThem(x,o);
System.out.println();
System.out.println("Back in the original method");
System.out.println("The value of o.x is " + o.x);
System.out.println("But.The value of x is now " + x);
}
public void changeThem(int x,xObject o){
x=9;
o.x=9;
System.out.println("In the changThem method");
System.out.println("The value of o.x is " + o.x);
System.out.println("The value of x is now " + x);
}
public static void main(String args[]){
passingDemo myDemo=new passingDemo();
myDemo.fist();
}
class xObject{
public int x=5;
}
}
输出结果
In the changThem method
The value of o.x is 9
The value of x is now 9
Back in the original method
The value of o.x is 9
But.The value of x is now 5
为什么输出顺序是从changeThem开始的。为什么first方法里的o.x变成9了
还有值传递和引用传递是怎么进行的。满意加分
展开