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.
Ans:- c
Hi Guru,
"Hello" and "Pal" are string objects which are created in pool. s1 and s2 point to the same "Hello" object in pool whereas "HelloPal" is another object which is created during concatenation pointed by s3 and s4. Therefore total object in a pool is 3.
Remember whenever you use a different string in your program e.g. "pal" a pool object is created.
Regards
Gaurav
SCJP 1.5