Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Must subclasses implement interfaces that their super-classes implement?

 
Jed Cousin
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I create sub-class 'bar' that extends class 'foo', and class foo implements interface 'baz', must sub-class bar also implement interface baz?
 
Jimmy Die
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,



No.

Bar will extend the methods you implemented in foo (and the ones you did not provide implementations for if any). If you did not provide concrete implementations of the methods from baz in foo, then foo is abstract. If bar doesn't provide concrete implementations of these methods then bar will also be abstract.
 
Jed Cousin
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, so baz becomes an integral part of foo (or bar) once the interface's abstract methods are made concrete. Thus obviating the need for a subclass (bar) to implement a superclass' interface (baz), as it's already been 'Borg-ed' by the superclass (foo).

Thanks man!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic