This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Answers to Review Questions - Chapter 5 - Question 17 (Sybex)

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code is:



The answer (B) says there is only a single compilation error with line 2 (or line 4 in my example above).

But my answer was that line 8 (line 12 in my example) was also in error because Orca doesn't provide an implementation of dive() (despite the code for the abstract method itself not being correct).

When you compile this code (with javac 1.8.0_131) you get two compilation errors:

javac -d ..\bin oca8\ch5\reviewquestions\q17\Whale.java
oca8\ch5\reviewquestions\q17\Whale.java:4: error: abstract methods cannot have a body
       public abstract void dive() {};
                            ^
oca8\ch5\reviewquestions\q17\Whale.java:12: error: Orca is not abstract and does not override abstract method dive() in Whale
class Orca extends Whale {
^
2 errors


So there are two compilation errors (for my compiler).

Is the book's answer correct?
 
author & internet detective
Posts: 40035
809
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul,
Welcome to CodeRanch!

Note that answer B is "The code will not compile because of line 2". It does not say in that answer choice that there aren't other compiler errors. Books (and the cert) often ask about the first compiler error because some compilers behave differently in the presence of multiple errors.
 
Paul Langtree
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeanne,

I must have missed that this question wasn't a 'Choose all that apply' question.  My mistake, apols.

Maybe the question could ask for the first (if any) compiler error?  I think even if I had read the question correctly, and realised there was only one answer (to be supplied by the reader), I still would have been confused by thinking there were 2 'right' answers.

Thanks for your reply.

Paul.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Gr wrote:Maybe the question could ask for the first (if any) compiler error?  I think even if I had read the question correctly, and realised there was only one answer (to be supplied by the reader), I still would have been confused by thinking there were 2 'right' answers.


Keep in mind that on the actual exam you will not be able to make that mistake as it clearly states how many correct answers you need to select.
 
    Bookmark Topic Watch Topic
  • New Topic