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.
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.
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.
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.