Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Number of Objects

 
Ravi Yadav
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 220
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems 4 for me ?


I am confused too...
[ November 01, 2008: Message edited by: Anut Walidera ]
 
Christina Pong
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any way to check the number of objects being created during the execution? Thanks :-)
 
long meng
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think there are 5 String objects: "Fred","47","Fred47","ed4","ED4"
 
pradeepta chopra
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i completely agree with long meng
there should be 5 objects
 
Ravi Yadav
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So the answere must be wrong...
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15485
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic