| Author |
Number of Objects
|
Ravi Yadav
Greenhorn
Joined: Mar 02, 2008
Posts: 29
|
|
This is from CertSCJP study material... 11. public String makinStrings() { 12. String s = �Fred�; 13. s = s + �47�; 14. s = s.substring(2, 5); 15. s = s.toUpperCase(); 16. return s.toString(); 17. } How many String objects will be created when this method is invoked? A. 1 B. 2 C. 3 D. 4 E. 5 F. 6 ANSWER: C Can someone tell me why the # of objects is 3?
|
 |
Tuna Töre
Ranch Hand
Joined: Aug 17, 2008
Posts: 219
|
|
It seems 4 for me ? I am confused too... [ November 01, 2008: Message edited by: Anut Walidera ]
|
blog: http://tunatore.wordpress.com
SCJP 6.0 + SCWCD 1.5
|
 |
Christina Pong
Greenhorn
Joined: Sep 21, 2008
Posts: 8
|
|
|
Is there any way to check the number of objects being created during the execution? Thanks :-)
|
 |
long meng
Ranch Hand
Joined: Oct 10, 2008
Posts: 58
|
|
|
i think there are 5 String objects: "Fred","47","Fred47","ed4","ED4"
|
SCJP 5.0 98%<br />SCWCD 5.0 in progress . . .
|
 |
pradeepta chopra
Ranch Hand
Joined: Jul 05, 2008
Posts: 137
|
|
i completely agree with long meng there should be 5 objects
|
 |
Ravi Yadav
Greenhorn
Joined: Mar 02, 2008
Posts: 29
|
|
|
So the answere must be wrong...
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12929
|
|
This exact question has been discussed many times on the forum here. Click on the Search link at the top right of the page and search for "Fred 47", and you'll find a lot of old posts about this question.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
 |
|
|
subject: Number of Objects
|
|
|