Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract method overriding method in parent class

 
Thomas Hauck
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question: Is it still considered method overriding when the abstract method in the abstract class Mammal has the same name as
the non-abstract method in Animal?
Is it still considered polymorphism when the overriding method in the subclass is abstract?



 
Roel De Nijs
Sheriff
Posts: 9927
112
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thomas Hauck wrote:Is it still considered method overriding when the abstract method in the abstract class Mammal has the same name as the non-abstract method in Animal?

Yes! The class Mammal is overriding the method speak from class Animal, but instead of providing an implementation it forces the (concrete) subclass to provide the implementation.

Thomas Hauck wrote:Is it still considered polymorphism when the overriding method in the subclass is abstract?

I would say "no", because a subclass with an abstract method must be abstract itself and you can't instantiate from this class. So in your example Animal a = new Mammal(); won't compile. When you create an anonymous subclass of Mammal by implementing the abstract method you'll definitely have polymorphism as shown in this example:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic