This week's book giveaway is in the Design and Architecture forum.
We're giving away four copies of Communication Patterns: A Guide for Developers and Architects and have Jacqui Read on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Multiple Inheritance in Java

 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Shishio San
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I forgot to mention that an interface can extend more that one interface.
 
Cowgirl and Author
Posts: 1589
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
30 seconds to difuse a loaf of bread ... here, use this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic