This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Multiple Inheritance in Java" Watch "Multiple Inheritance in Java" New topic
Author

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:
Thomas
Shishio San
Ranch Hand

Joined: Aug 29, 2002
Posts: 223
Hi,
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
Ranch Hand

Joined: Oct 10, 2002
Posts: 1572
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 <a href="http://www.amazon.com/exec/obidos/ASIN/0596007124/ref=jranch-20" target="_blank" rel="nofollow">"Head First Design Patterns"</a><br /> <br />Just a Jini girl living in a J2EE world.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multiple Inheritance in Java
 
Similar Threads
Inner class question
interface
Easy Queries
is-a relationship
Multiple Interface Inheritance / Interface Inheritance