我把程序给你万万全全的改了一下: public class PassingDemo{ public void first(){ XObject o=new XObject(); o.x=5; int x=5; changeThem(x,o); System.out.println(); System.out.println("Back in the original metod"); System.out.println("The value of o.x is now"+o.x); System.out.println("But,The value of x is still"+x);
} public void changeThem(int x,XObject o){ x=9; o.x=9; System.out.println("In the changeThem method"); System.out.println("The value of o.x was changed to "+o.x); System.out.println("The value of x was changed to "+x);
} public static void main(String args[]){ PassingDemo myDemo=new PassingDemo(); myDemo.first(); } } class XObject{ public int x; }除了楼上两位说的System.out.printIn --->System.out.printlnpublic static void main(string args[]) ---> public static void main(String args []) 外,你还应该注意类名的一一个字母要大写!
public class PassingDemo{
public void first(){
XObject o=new XObject();
o.x=5;
int x=5;
changeThem(x,o);
System.out.println();
System.out.println("Back in the original metod");
System.out.println("The value of o.x is now"+o.x);
System.out.println("But,The value of x is still"+x);
}
public void changeThem(int x,XObject o){
x=9;
o.x=9;
System.out.println("In the changeThem method");
System.out.println("The value of o.x was changed to "+o.x);
System.out.println("The value of x was changed to "+x);
}
public static void main(String args[]){
PassingDemo myDemo=new PassingDemo();
myDemo.first();
}
}
class XObject{
public int x;
}除了楼上两位说的System.out.printIn --->System.out.printlnpublic static void main(string args[]) ---> public static void main(String args [])
外,你还应该注意类名的一一个字母要大写!