I tried this code.
public class CopyOfMain {
public static void main(String[] args) {
CopyOfMain c = new CopyOfMain();
Emp e = new Emp();
e.setName("Mick");
c.edit(e);
System.out.println(e.getName());
String s = new String("hello");
c.edit(s);
System.out.println(s);
}
public void edit(Emp s) {
s.setName("mickey");
}
public void edit(String s) {
s.concat("world");
}
}
Output
:
mickey hello
WHy name in emp has changed ? But not with the string parameter? Is it because it is immutable class?
And If yes, then name
in String is also immutable
?
So how does first name get updated but not second?
THanks.