Page 1 of 1

Doubt from some book - How many String objects

Posted: Sat Aug 09, 2014 3:45 am
by hamada.yamasaki
Hi,
I got little confused after this question. If i apply the knowledge gain from this question, then there must be 9 String object created but the author mentioned 8
String s1 = "spring ";
String s2 = s1 + "summer ";
s1.concat("fall ");
s2.concat(s1);
s1 += "winter ";
System.out.println((s1 + " " + s2));
Here are the instance which i thought:
spring
summer
spring summer
fall
spring fall
spring summer spring
winter
spring winter
spring winter spring summer // the author is not taking this instance into account

Could you please explain. Thanks a lot

Re: About Question enthuware.ocajp.i.v7.2.1303 :

Posted: Sat Aug 09, 2014 10:47 am
by admin
Hamada, I couldn't find this question in our question bank. Are you sure you saw it in our question bank? I checked question 2.1303 and it is very different from what you've quoted.
-Paul.

Re: About Question enthuware.ocajp.i.v7.2.1303 :

Posted: Sat Aug 09, 2014 12:06 pm
by hamada.yamasaki
i am sorry i didn't noticed that it was mentioned in the book not in enthuware.
Is it possible for you to still provide some explanation ?
Thanks and once again sorry for the mistake

Re: About Question enthuware.ocajp.i.v7.2.1303 :

Posted: Sat Aug 09, 2014 10:18 pm
by admin
Yes, 9 seems right. Not sure why the author says 8.
The book probably costs more than our s/w. Didn't the author respond to your doubt?
-Paul.