File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question about number of objects created Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question about number of objects created" Watch "Question about number of objects created" New topic
Author

Question about number of objects created

Marco Farrugia
Ranch Hand

Joined: Jul 20, 2012
Posts: 33
1. StringBuffer s1 = new StringBuffer("abc");
2. StringBuffer s2 = s1;
3. StringBuffer s3 = new StringBuffer("abc");

How many objects are created ?

My answer is 3, but the exam practice I am using says 4. Can someone confirm please? I know the exam practice I am using contains a lot of mistakes, so I am not trusting it.
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1666
    
    7

Two StringBuffer instances and one String instance, as the literal value "abc" will end up in the String constant pool as a single instance.
So that makes three objects, like you said.

Also, please don't forget to QuoteYourSources (<-click): which practice exam are you using?


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Marco Farrugia
Ranch Hand

Joined: Jul 20, 2012
Posts: 33
I did not want to give the source a bad name by saying that there are lots of mistakes, but that's the truth, but not that I inserted the name of the website, the forum is not allowing me to add it because it is banned. Anyway it's tf360 and I doubt it that it is giving real questions for 1Z0-804 (some are too easy, others have mistakes in answers as well as spelling). In fact I am going to look for another one.

I desperately need suggestions for a good 1Z0-804 exam practice with correct answers, matching choice of topics and good explanations!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question about number of objects created
 
Similar Threads
How many objects created?
how many objects are created?
Question on Garbage Collection
number of objects created
RHE question - String buffer