• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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

 
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.
 
author & internet detective
Marshal
Posts: 38506
653
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

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!