• Post Reply Bookmark Topic Watch Topic
  • New Topic

abstract Implementation classes for Interfaces  RSS feed

 
yaswanth yash
Greenhorn
Posts: 12
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why an abstract class can miss the implementation of its interface methods...

what is the relationship between an Interface & its abstract implementation class...

An exceptional case for abstract classes?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abstract classes can avoid implementing interface methods for the same reason as they can declare abstract methods.

The important thing is that any concrete instance of a class must have a defined body for any method it has. Otherwise, what's going to happen if that method gets called? So a concrete class must have an implementation for every method it owns (either in its own body or inherited). But an abstract class can't be instantiated, so that danger doesn't exist. As long as any concrete subclasses implement the method, it's all safe.
 
Paul Clapham
Sheriff
Posts: 22835
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yaswanth yash wrote:Why an abstract class can miss the implementation of its interface methods...


As you know, an abstract class can declare a method as abstract, which means that a subclass of the abstract class must provide an implementation (or in turn declare that method to be abstract). This is true whether or not the abstract class happens to implement an interface which declares that method.

what is the relationship between an Interface & its abstract implementation class...


Just like any other class... the abstract class implements the interface.

An exceptional case for abstract classes?


No, quite the contrary. You're the one trying to make up exceptional cases by imagining special rules for methods which are inherited from an interface. But no such special rules exist and no exceptional cases either.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!