wood burning stoves*
The moose likes Java in General and the fly likes Multiple Inheritance in interface ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Multiple Inheritance in interface ?" Watch "Multiple Inheritance in interface ?" New topic
Author

Multiple Inheritance in interface ?

Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
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 ?
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
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.


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Ahetuki Neti
Greenhorn

Joined: May 29, 2003
Posts: 20
Moreover, while writing anonymous inner classes you will realize the importance of multiple inheritance of interfaces!


Ahetuki, the Constant.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multiple Inheritance in interface ?