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

Why a non-abstract Parent Class can be extended by an abstract Child Class ?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

My question is why a non-abstract Parent Class can be extended by an abstract Child Class ?

Take a look at the following code:-



This code compiles fine and when it is executed it gives the following output:-
Inside method1() AbstractTest

Now in the class AbstractTest if the following three lines are commented :

then the code gives compilation error:
AbstractTest is not abstract and does not override abstract method method1() in Child

In summary, a non-abstract parent class (Parent) can be extended by an abstract child class (Child). Now this means that all the methods decared in the parent class (method1()) get replaced by the corresponding method signatures in the abstract child class. Is there any specific reason why this is allowed in JAVA ?

Thanks in advance.

Avirup
 
Marshal
Posts: 25669
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The main reason it's allowed is so that you can have abstract classes. Remember that all classes, unless declared otherwise, are subclasses of Object -- which is NOT abstract.
 
Ranch Hand
Posts: 537
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try overriding a non abstract method with a abstract method.
 
avi neo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul !!!
 
Proudly marching to the beat of a different kettle of fish... while reading this tiny ad
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic