This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi Jeff lets see 1.String s1="hello" creates String object "hello" on the heap with reference s1 to it.So 1 object in the heap.(1) 2.The second line assigns s2 reference to s1 ie to "hello" No objects are created here. 3.String s3 =s2+"pal"; Here "pal" is created(2). Since Strings are immutable, s2+"pal" returns a new String object "hellopal"(3).So Object number 3 in the heap 4.This does nothing except for assigning a new reference to s3. So there are 3 objects created .Since "pal" has no reference after line 3,It'll be eligible for garbage Collection. ------------------ Pravin R Panicker Sun Certified Java Programmer