• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Question about number of objects created

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Marco Farrugia
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!!
 
It runs on an internal combustion engine. This ad does not:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic