I have a string in method in java class as below
public void show(){
String s1;
s1 = "abc";
s1 = "def";
System.out.println(s1);
}
Here the output is def, but as String is immutable so I don't understand how string s1 is immutable here as I can change the String s1 content from abc to def.
Could you please make me understand this?
No comments:
Post a Comment