• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sybex OCAJP 8 Online material: StingBuilder question

 
Greenhorn
Posts: 10
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,

I just came across this question earlier and was racking my brain trying to figure it out. I understand that equals() is not overridden in StringBuilder, so the references are compared and should return false as they're two different objects. So I can't see how this would produce two (after the non-compiling line is removed).



I ran this and commented the third if statement. It didn't produce any output.

Am I missing something?



 
Ranch Hand
Posts: 56
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Simon, it's clearly a mistake in the test. Notice that in the solutions description it says:

StringBuilder does not implement the equals method, so you cannot compare their values using the equals() either.



I actually have the OCA test scheduled to be taken tomorrow. Hopefully they don't have these kind of mistakes
 
Simon Miller
Greenhorn
Posts: 10
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reassurance Vyacheslav, I was pretty sure it was a mistake after running it but I've had trouble with String/StringBuilder comparisons so I second guessed myself.

Best of luck for tomorrow!  
 
Bartender
Posts: 1251
87
Hibernate jQuery Spring MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Simon Miller,
Welcome to CodeRanch!    will you please QuoteYourSources ? ( Sybex online material Or text book etc )so this thread will be useful for others too, who may face same problem.

Vyacheslav Belenky, best of luck for the exam.
 
Simon Miller
Greenhorn
Posts: 10
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ganesh Patekar wrote:Simon Miller,
Welcome to CodeRanch!    will you please QuoteYourSources ? ( Sybex online material Or text book etc )so this thread will be useful for others too, who may face same problem.

Vyacheslav Belenky, best of luck for the exam.



Thanks for the welcome. The question being referred to is part of the online tool that's bundled with Boyarsky and Selikoff's 'OCA: Oracle Certified Associate Java SE 8 Programmer I Study Guide: Exam 1Z0-808'. It appeared as question 32 in the second 60-question mock exam.
 
Ganesh Patekar
Bartender
Posts: 1251
87
Hibernate jQuery Spring MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for information.  
 
First, you drop a couch from the plane, THEN you surf it. Here, take this tiny ad with you:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic