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

Wrong explanation for Q46 from online content (Sybex OCA Java 8 Study Guide))

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

i clicked through the online practice exam. There is one Question 46, which asks you to find out if a String is equal / a String reference is the same as another String.

The question is tricky, because it uses String.equal()-Method instead of equals().

The code:

String s = "Hello";
String t = new String (s);
if ("Hello".equals(s)) System.out.println("one");
if (t == s) System.out.println("two");
if (t.equals(s)) System.out.println("three");
if ("Hello" == s) System.out.println("four");
if ("Hello" == t) System.out.println("five");



I was mislead by the question and so i read the explanation really carefully.
The explanation says: "... If equals() were in this code, the answer would be options A, C and E."

This is wrong, because if equals would have been used in the code, the answer would be options A, C and D.
 
author & internet detective
Posts: 41763
887
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dominik,
Thanks for reporting the issue. I've logged it on our errata page. I am going to report it to Wiley for fixing, but I'm going to wait a couple weeks. It's easier for them to fix a few things at a time so I want to see if more accumulate.
 
Something about .... going for a swim. With this tiny ad ...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic