调用p.name = "EJava";
方法后不应该改变anotherMethod(p);
吗?谁能解释为什么此代码返回:
anotherMethod
EJava
someMethod
someMethod
代替 :
anotherMethod
anotherMethod
someMethod
someMethod
班级人
class Person {
public String name;
public int height;
}
测试仪
class EJavaGuruPassObjects1 {
public static void main(String args[]) {
Person p = new Person();
p.name = "EJava";
anotherMethod(p);
System.out.println(p.name);
someMethod(p);
System.out.println(p.name);
}
static void someMethod(Person p) {
p.name = "someMethod";
System.out.println(p.name);
}
static void anotherMethod(Person p) {
p = new Person();
p.name = "anotherMethod";
System.out.println(p.name);
}
}
调用p.name = "EJava";
方法后不应该改变anotherMethod(p);
吗?