Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple Interface Inheritance / Interface Inheritance

 
kri shan
Ranch Hand
Posts: 1473
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inteface A

Interface B extends A ---> Is it Interface Inheritance ?

Class C implements B --> Is it Multiple Interface Inheritance ?

Java does not support Interface Inheritace.

 
fred rosenberger
lowercase baba
Bartender
Posts: 12185
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
an interface is a contract - nothing else. When you have

Interface A {}

you are saying "here are the rules for what it means to implement the 'A' interface.

When you say "implements A", you are saying "This class/abstract class will implement everything required by the A interface"

so,

interface B extends A

is just saying "here are the rules for implementing the B interface, which by the way, must also implement the A interface."

and "Class C implements B" is just saying "I promise that the C class will implement everything required by the B interface (which just so happens to also require implementation of the A interface".

it's not really inheritance at all.

 
Jarred Olson
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:

interface B implements A



Just a nitpick, but interfaces extend other interfaces, not implement.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12185
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops...
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15441
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Multiple inheritance means: a class that extends two classes.

But if you make a "chain": B extends A, and C extends B - then that is not multiple inheritance.

Java doesn't have multiple inheritance because it causes some hard problems like the diamond problem and because it's not an essential feature. A large part of Java was designed to look like C++, but with the hard parts left out. This is an example of a C++ feature that was left out of Java.

See http://en.wikipedia.org/wiki/Multiple_inheritance
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic