Should'nt p.name = "EJava";
being altered after method anotherMethod(p);
was invoked ?
Can anyone explain why this code returns :
anotherMethod
EJava
someMethod
someMethod
instead of :
anotherMethod
anotherMethod
someMethod
someMethod
Class Person
class Person {
public String name;
public int height;
}
Tester
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);
}
}
Should'nt p.name = "EJava";
being altered after method anotherMethod(p);
was invoked?