File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Number of Objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Number of Objects" Watch "Number of Objects" New topic

Number of Objects

Ravi Yadav

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

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 ]

SCJP 6.0 + SCWCD 1.5
Christina Pong

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

Joined: Mar 02, 2008
Posts: 29
So the answere must be wrong...
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074

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
It is sorta covered in the JavaRanch Style Guide.
subject: Number of Objects
Similar Threads
String Objects
How many String Objects are created by executing the following method
How many string objects
Question on String
Mock Exam Ques-.No of String objectss creation