Hi, I would like to know the answer for this question. How many strings are created in the follo program. String s1,s2,s3,s4; s1 = "Hello"; s2 = s1; //s2="Hello" s3 = s2 + "Pal"; //s3="Hello Pal" s4 = s3;//s4="Hello Pal" According to me, 2 strings(Hello & Hello Pal) are created. But the ans given is 3. can anyone explian this? -Sanjana
A new String is created at s1. s2 points to the same string as s1 but no new strings are created. A new String "Pal" is created (which makes the count now to 2) and another string forming "Hello Pal" (count now is three). s4 points to the same string as s3 but no new strings are created.