class Main {
public static void main(String[] args) {
String s1 = "xy";
String s2 = s1;
s1 = s1 + s2 + "z";
System.out.println(s1);
System.out.println(s2);
}
}
When I ran the code i was expecting to get something like this, because the value of s1=s2 :
xyxyz
xyxyz
But the actual output is:
xyxyz
xy
I am unsure why i don't get the same answer? Is it because the line of code changing s1 to the value "xyxyz" was ran after making s1=s2?