Yeap..the answer is B. Here are some points to keep in mind.
1.when you do String s = "Hello"; //one object is created
2.when you do String s2 = s; //no object is created because the object from the string pool is referenced by s2
3.when you do String s3 = s+"Pal"; //one object is created because this is a new string (HelloPal).
4.Again when you do String s4 = s3; //no object is created because the object from the string pool is referenced.
I hope this explanation helps..
Roopa
Originally posted by Fisher Daniel:
Hi all,
I take this from Valiveru's Home
Question 45.
How many String objects are created when we run the following code.
String s1,s2,s3,s4;
s1 = "Hello";
s2 = s1;
s3 = s2 + "Pal";
s4 = s3;
A.1
B.2
C.3
D.4
E.We can't say.
And the answer is C. Can you help me about it?
thanks
daniel