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; i think 2, but the mock exam answer says 3 pls explain. Thanx in advance
I think 3.....Following this process. First Hello will be created.Understanding of this line should me made carefully, s3 = s2 + "Pal"; Now compiler have to concate the two string objects.It will search the two strings first in the pool if it gots one then it will pick this & start searching another one.In both cases if String objects is not found it will create one by it self and then concate it with another one. In this case it will pick the string object pointed by s2(i.e Hello) & make Pal by it self and then concate both Pal & Hello.If you analyse u will find that total of THREE objects is made altogether This is my thinking....May be i am wrong.So plz. confirm it! Bye. Viki.
------------------ Count the flowers of ur garden,NOT the leafs which falls away!
• Sun Certified Programmer for Java 2 Platform (SCJP2)
• IBM Certified Professional for Object Oriented Analysis and Design with UML
• IBM Certified System Administrator for WebSphere Application Server v5.0
• Certified Business Analysis Professional (CBAP®)
Thanks 4 confirming David. Bye. Viki. ------------------ Count the flowers of ur garden,NOT the leafs which falls away!
• Sun Certified Programmer for Java 2 Platform (SCJP2)
• IBM Certified Professional for Object Oriented Analysis and Design with UML
• IBM Certified System Administrator for WebSphere Application Server v5.0
• Certified Business Analysis Professional (CBAP®)
Don't get me started about those stupid light bulbs.