my dog learned polymorphism
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Multiple Inheritance in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Multiple Inheritance in Java" Watch "Multiple Inheritance in Java" New topic

Multiple Inheritance in Java

Thomas Markl
Ranch Hand

Joined: Mar 08, 2001
Posts: 192
This code compiles fine. I always thought it is not possible to state more than one class after "extends"?
interface Int_A {}
interface Int_B {}
class A{}
class B{}
class C extends A, B {}
interface Test extends Int_A , Int_B {}
Appreciate your answers:
Shishio San
Ranch Hand

Joined: Aug 29, 2002
Posts: 223
You can't extend more than one class but you can implement more than one interface. I think you know that already. The code you posted flags a compile time error when it reaches
class C extends A, B {}
Maybe you should try to compile it again.

Whatever doesn't kill us ...<br />Is probably circling back for another try.<br />SCJP 1.4
Shishio San
Ranch Hand

Joined: Aug 29, 2002
Posts: 223
I forgot to mention that an interface can extend more that one interface.
Kathy Sierra
Cowgirl and Author

Joined: Oct 10, 2002
Posts: 1589
Interfaces can always extend other interfaces, since this presents no multiple inheritance problem. Whoever first implements an interface must provide implementations for everything in that interface, PLUS, everything in all the superinterfaces (i.e. the interfaces your interface extends, and any that *they* extend, and so on all the way up).
Just a side note about one place this is used...
This is used especially in EJBs where you might have a business interface (with just business logic) and then a component interface that extends both Remote (which it must, for RMI) and also the business interface. Then your enterprise bean can extend just the business interface and everyone is happy.

Co-Author of Head First Design Patterns
Just a Jini girl living in a J2EE world.
I agree. Here's the link:
subject: Multiple Inheritance in Java
It's not a secret anymore!