Michael Dixon wrote:
The anonymous string object "c" in lines 1 and 2 is the same. The object is a string literal. String literal is placed in the string constant pool, on the heap, by the JVM. Each time a literal is encountered, the pool is checked to determine if it exists. If it exists, it is reused. Otherwise a new one is created and placed in the pool.
The anonymous string object "c" is created at line 1. At line 2, when it is encountered the pool will be checked. Since it exists it will be reused.
BTW, the code will not compile because a } is missing.
So It means 6 String Objects are created, One string object on each line, except for line 1 where two String objects are created( "c" and s3), please correct me if i am wrong
Thanks in advance