• Post Reply Bookmark Topic Watch Topic
  • New Topic

Missleading solution in chapter 4 of OCA Oracle Certified Associate Java SE 8 Programmer 1  RSS feed

 
Michael Migs
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

In the book "OCA Oracle Certified Associate Java SE 8 Programmer 1" by Jeanne Boyarsky and Scott Selikoff. Review question #19 is testing our ability to understand when default constructors are used. The answer provided page 345 mentions that answers B and C are not valid because Java is case sensitive and the statements "bird()" don't match the constructor which should be written with a capital "B" "Bird()". This is true however it is not the real reason why this code is wrong. Java is trying to math "bird()" to a standard method but it cannot because it does not have a return type. Trying to compile this actually writes the error:

When adding the "void" return type, the code compile fine. This means that a constructor "Bird()" can cohabitate with a method "bird()". So if void was added, the default constructor would have been used. This means that the only reason B and C are wrong is because the return types are missing.

I think this deserves to be specified in the answer to avoid confusing people into thinking that "Bird()" constuctor cannot cohabitate with "bird()" method.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37399
531
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael,
True, good point. You are correct that they do compile. Still wrong off course as the question asks about constructors.

I added this to our list of things that could be clearer. Thanks for pointing it out.
 
Michael Migs
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm glad I could help

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!