File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A question from K & B book Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "A question from K & B book" Watch "A question from K & B book" New topic

A question from K & B book

Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
3. Given the following,
1. abstract class A {
2. abstract short m1() ;
3. short m2() { return (short) 420; }
4. }
6. abstract class B extends A {
7. // missing code ?
8. short m1() { return (short) 42; }
9. }
which three of the following statements are true? (Choose three.)
Self Test 135
A. The code will compile with no changes.
B. Class B must either make an abstract declaration of method m2() or implement
method m2() to allow the code to compile.
C. It is legal, but not required, for class B to either make an abstract declaration of method
m2() or implement method m2() for the code to compile.
D. As long as line 8 exists, class A must declare method m1() in some way.
E. If line 6 were replaced with �class B extends A {� the code would compile.
F. If class A was not abstract and method m1() on line 2 was implemented, the
code would not compile.

Answer is A,C and E. I have following doubts about C:
1. The phrase "It is legal but not required.....
for code to compile"
If it is not required why will it not compile.
2. How can you redefine a concrete method from super class as abstract method in subclass?
3. If code is compilable as it is (per correct answer A), why do need to either changes outlined in C for it to compile?
Thanks for your help.
Kathy: Your book is excellent from exam point of view and readibility. Thanks.....
G Nadeem
Ranch Hand

Joined: Apr 25, 2003
Posts: 48
Hi Barkat,

1) presumabably C is saying, "for a compileable code to compile" and not "for an uncompileable code to compile.". so C is NOT saying that code in its current will not compile.
2) this is possible. however access to super class method functionality is lost
3) this is automatically resolved once '1' is resolved.
i do however agree that some degree of ambiguity does exist in the question.
hope it helps.
Bert Bates

Joined: Oct 14, 2002
Posts: 8898
Hi Barkat -
First off, I think you're saying that the code as it stands won't compile. It compiles for me, what error message do you get?
Secondly, what question do you have about answer C? (It IS saying that any of the three options are legal.)
It is legal to override a concrete method in an abstract class with an abstract method. As the developer, you might decide that whoever subclasses your class must re-implement the method in question, and this is how you would accomplish that.
Does that help?

Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
Hi Bert,
The text of option C is little confusing. In one sentence, it is says " is not required...." and finishes of by saying " compile.
However, I did not know that a concrete method can be overridden by an abstract method. I thought it is vice versa. Is it discussed somewhere in the book in detail?
Thanks for your response.
I agree. Here's the link:
subject: A question from K & B book
It's not a secret anymore!