• 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
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

RE:Question from K&B book

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's overriding.
BTW thanks for changing your displayed name so quickly
-Barry
 
Does this tiny ad smell okay to you?
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic