|
because you are not changing the String, you are changing what the 's' reference points to.
in other words, 's' is NOT a String, it is a REFERENCE TO a String. 's' lives on the stack, and the String object containing "abcde" lives in the heap (let's not get into the String pool right now). when you run the line
s= "12345", a new String is created in the heap. 's' is changed to point to it, but the String "abcde" is still hanging around, unchanged.
|