Consider the code
String s="hello";
s=s.concat("java");
As String objects are immutable so new object should be created with value “Hello Java” referenced by S.
Now my query is that where is that earlier String object “hello” referenced by s initially gone?
Does it still exist in memory? if so then how? because in Java the life time of object remains only till it’s reference exist. In case of “hello” it’s reference had lost when second statement executed. so how can it still exist in memory???
Please someone solve my doubt. :)