Java supports multiple inheritance of types. A class can have many types, each defined by an interface. But Java does not support multiple inheritance of implementation. A class can inherit actual code from just one other class.
Not every language makes this kind of distinction.
This is the heart of polymorphism: A class that implements multiple interfaces can be treated as though each its objects were an object of that interface's type, so the object could be added to a collection of the interface type.
Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4 all those years ago...)
Implementing multiple interfaces is a very limited version of multiple inheritence because it does not allow you to inherit any implementation, as stated above. In contrast, C++ allows full-blown multiple inheritence. That is it allows one class to "extend" multiple base classes. Each of the base classes are full classes, which means they can include some implentation details if necessary.
When people say that Java does not have multiple inheritence, they typically mean that a class cannot inherit from multiple base classes. Many other object-oriented languages provide full support for multiple inheritence whereas Java's support is very limited.
Originally posted by sreedhara satuluri: there was a heated discussion in that affair and it went very long but no solution
Depends on what you call a solution... Of course the people screaming that Java should have multiple inheritance a-la C++ say there's no solution, but sane people agree that there is a perfectly working solution and that's interfaces.
One justification of not allowing multiple inheritance in JAVA is to avoid the well known diamond problem with multiple inheritance in C++. Let me give a quick explanation about the diamond problem. Consider a class called Parent which has a method called MyMethod, now let two classes say Child1 and Child2 inherit from this class Parent, each of them have an implementation of the method MyMethod. Now Consider a class GrandChild which multiply inherits from Child1 and Child2 and it does not have an implementation of MyMethod. Now if an Object of GrandChild makes a call to MyMethod there is an ambiguity as to which method should be called.
In Java, interfaces solve all these ambiguities caused by the diamond problem. Through interfaces, Java allows multiple inheritance of interface but not of implementation. Implementation, which includes instance variables and method implementations, is always singly inherited. As a result, confusion will never arise in Java over which inherited instance variable or method implementation to use.
the Python programming language also has multiple inheritance (of implementation), and frankly, i think it's barely worth its effort from what i can see. it brings with it some fairly hairy issues of precedence resolution that's taken several language revisions and several years to get more or less resolved. (see, for example, version 2.2.1, version 2.3.1, or -- for purely archaeological interest -- version 1.5.2.)
multiple inheritance (of either major kind) enables the use of Mix-ins, which is a major win. interface inheritance forces you to rewrite the code for the mixed-in methods in each class you use them in, which might create a good deal of duplication; but multiple implementation inheritance gives you the "diamond rule" headache. any problem that needs a bunch of Common Lisp/Dylan aficionados to write a scholarly paper about its solution (this paper) is not a problem you want to tackle lightly.