Think it as Like this,
When first Variable
Str
is initialized with "abc" then Literal "abc" gets memory in String Pool so variableStr
gets reference to this "abc".Str
-------------------------------->abc
On Second Step, in similar fashion another variable reference to same literal in String Pool .
Str
-------------------------------->abc
<-------------------------------Str1
In final Step , if considered
String Str
then anError
will occur like this:-variable Str is already defined
So instead i will take
Str = "xyz"
on doing this aNew
literal will get memory in String Pool andStr
previous reference will be deleted and new reference will be assigned.Str
-----------X------------->abc
<-----------------------Str1
Str
-------------------------->xyz
Finally we will get this and will have 2 Literals namely
abc
andxyz
in String PoolStr
-------------------------->xyz
andStr1
-------------------------->abc