Why is there no multiple inheritance in Java, but implementing multiple interfaces is allowed? Why is there no multiple inheritance in Java, but implementing multiple interfaces is allowed? java java

Why is there no multiple inheritance in Java, but implementing multiple interfaces is allowed?


Because interfaces specify only what the class is doing, not how it is doing it.

The problem with multiple inheritance is that two classes may define different ways of doing the same thing, and the subclass can't choose which one to pick.


One of my college instructors explained it to me this way:

Suppose I have one class, which is a Toaster, and another class, which is NuclearBomb. They both might have a "darkness" setting. They both have an on() method. (One has an off(), the other doesn't.) If I want to create a class that's a subclass of both of these...as you can see, this is a problem that could really blow up in my face here.

So one of the main issues is that if you have two parent classes, they might have different implementations of the same feature — or possibly two different features with the same name, as in my instructor's example. Then you have to deal with deciding which one your subclass is going to use. There are ways of handling this, certainly — C++ does so — but the designers of Java felt that this would make things too complicated.

With an interface, though, you're describing something the class is capable of doing, rather than borrowing another class's method of doing something. Multiple interfaces are much less likely to cause tricky conflicts that need to be resolved than are multiple parent classes.


Because inheritance is overused even when you can't say "hey, that method looks useful, I'll extend that class as well".

public class MyGodClass extends AppDomainObject, HttpServlet, MouseAdapter,              AbstractTableModel, AbstractListModel, AbstractList, AbstractMap, ...