Win a copy of Microservices in Action this week in the Web Services forum!
  • 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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
Posts: 38925
686
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

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!