i read the link Abimaran refered
when you
come to the keyword "new," the JVM is obliged to create a new String object at run-time, rather than using the
one from the constant table.
the String object
referenced from the String Literal Pool is created when the class is loaded while the other String object is created
at runtime, when the "new String..." line is executed
so s3 would be assigned the value at runtime rather than at compile time
am i right ?
but ,s3 is not created using the new keyword,so it would have reference in string literal pool
as the link says:
the JVM goes through the code for
the class and looks for String literals. When it finds one, it checks to see if an equivalent String is already
referenced from the heap. If not, it creates a String instance on the heap and stores a reference to that object in
the constant table. Once a reference is made to that String object, any references to that String literal throughout
your program are simply replaced with the reference to the object referenced from the String Literal Pool
so,after line-7 there would be only one entry in the String Literal Pool, which would refer to a
String object that contained the
word "abcxyz". Both of the local variables, s5 and s4, would be
assigned a reference to that single String object.