wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes RE:Question from K&B book Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "RE:Question from K&B book" Watch "RE:Question from K&B book" New topic
Author

RE:Question from K&B book

guan di
Greenhorn

Joined: Mar 29, 2004
Posts: 4
hello all,
this is a question from K&B book pg 134 Q3.

which three of the following statements are true? (Choose three)
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 code to compile.
C. It is legal, but not required, for class B to either make an abstract declaration of method m2() or implement 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 replace 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.

Ans. A , C , E
i do understand the answer for A and E but the reasoning for C to be correct escapes me.
Can any one explain why C is true?
we can declare a concrete method in a superclass to be an abstract method in a subclass?
thanks in advance
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
"guandi" please change your displayed name to conform to JavaRanch's Naming Policy.
You can do that here.
Just use two names just like our other members do.
In the mean time I'll take a look at your question...
Thanks
-Barry


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
pallavi utukuri
Ranch Hand

Joined: Feb 10, 2004
Posts: 182
C. It is legal, but not required, for class B to either make an abstract declaration of method m2() or implement m2() for the code to compile.
we can declare a concrete method in a superclass to be an abstract method in a subclass?

this is compiling so i think we can declare a concrete method in a superclass to be an abstract method in a subclass.......what do u say barry???
(Barry added code tags)
[ April 18, 2004: Message edited by: Barry Gaunt ]

Thanks,<br />Pallavi
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
we can declare a concrete method in a superclass to be an abstract method in a subclass?

Cut and paste the code into an editor and try it. If you define

in class B it compiles. Class B is already declared as being an abstract class. Clearly, you would have to define a subclass of class B to implement that abstract short m2() method.
guan di
Greenhorn

Joined: Mar 29, 2004
Posts: 4

in class B it compiles. Class B is already declared as being an abstract class. Clearly, you would have to define a subclass of class B to implement that abstract short m2() method.

so does this counts as overriding or overloading?
[ April 18, 2004: Message edited by: Barry Gaunt ]
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
It's overriding.
BTW thanks for changing your displayed name so quickly
-Barry
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RE:Question from K&B book
 
Similar Threads
K&B book Chapter 2 Self Test Question No.3
Question on Declarations and Modifiers
Question#3 in K&B book question
A question from K & B book
abstract method INFO Plz?