• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Multiple Inheritance in interface ?

 
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java does not allow multiple inheritance for classes, but for interface it's possible to inherit from multiple interfaces ?. What the reason for this ?. Why does java allow multiple inheritance in interface and not for classes ?
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java does not allow multiple inheritance for classes, but for interface it's possible to inherit from multiple interfaces ?. What the reason for this ?. Why does java allow multiple inheritance in interface and not for classes ?
The main motivation for interfaces in java's beginning was to get away from multiple inheritance. If you really think about one interface extending another, it is not so much inheritance as it is concatenation. Class inheritance is a lot more than merely summing all the methods and instance variables. Classes must be instantiated thru the whole hierarchy from most specific instance to most general (always an instance of Object for java). Interfaces cannot be instantiated. Further consider the almost intolerable restriction that limiting interface implementation to a single interface. Class design would be greatly diminished. Having a class implement more than one interface is semantically equivalent to one interface extending the remaining interfaces.
The reason java does not allow multiple class inheritance is because it creates more problems than it solves for compiler, runtime and programmer. Take a look at this thread for a discussion on that subject.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moreover, while writing anonymous inner classes you will realize the importance of multiple inheritance of interfaces!
reply
    Bookmark Topic Watch Topic
  • New Topic