Fendel,
being a beginner aswell, I'll try to explain how I get to 3 objects:
Originally posted by Fendel Coulptz:
then how many string objects are created in this example? i don't understand why 3 objects are created.
String s1,s2,s3,s4;
s1 = "Hello";
s2 = s1;
s3 = s2 + "Pal";
s4 = s3;
1� object is "Hello" which is referenced by s1 and s2.
2� object is "Pal"
and the 3� object is the concatenation of "Hello" (referenced by s2) and "Pal", thus resulting in "HelloPal" being referenced by s3 and s4.
About the a1==a2 case, I believe there is a typo in
String a2 = "alibaba and forty theives";
If I'm wrong, please do forgive AND correct me.
More @ this link
The SCJP Tip Line [ October 27, 2004: Message edited by: Eric Zanders ]