public class test {
public static void main(String [] args) {
Person p = new Person("ABC");
p.setName("DEF");
changePerson(p);
System.out.println(p.getName());
}
public static void changePerson(Person p) {
p.setName("GHI");
p = new Person("JKL");
p.setName("MNO");
System.out.println(p.getName());
}
}
class Person {
String name;
Person(String name) {
this.name=name;
}
public void setName(String n) {
name = n;
}
public String getName() {
return name;
}
}
output is:
MNO
GHI
Please can anybody explain this? I could not understand.