Multiple Inheritance
What's the Big Deal?
Usually the term "multiple inheritance" refers to a class being
derived from, or extending, multiple classes. This is a much-debated
feature -- some languages have it, some do not. A lot of people hate it!
The problem is that classes can have implementation, and implementation
inheritance has a lot of ambiguities associated with it; it turns out
to be very complex and messy. Java does not have this: a class
can only extend one superclass.
Consider

and assume that d is an object of class D. We have quite a few
decisions to make.
- There is a name clash inheriting the field y from classes
B and C, making us wonder what the expression "d.y" might mean.
We could make it a compile time error to have the multiple
inheritance because of the name clash. We could allow the
the extension, but throw out the field y. We could also
envision d having either one or two fields called y (that is
we can "merge" the fields). If we don't merge them, we might
need some syntax like d.B::y and d.C::y (that is, require
"qualification").
- There is a name clash inheriting the field z from classes B and C.
Like in the previous item we could disallow the extension or
simply throw out the field z. Or we can envision having either
one or two fields called z. If one, WHICH one, B's or C's?
That is, would "d.z" have type Integer or String?
Do we resolve the ambiguity by alphabetical order or
by the name of the class that appeared first in the
"extends" clause of class D's declaration?
If two, we might need some syntax like d.B::z and d.C::z
(that is, require qualification).
- There is a name clash inheriting the operation g from
classes B and C. Like in the previous items we could
disallow the extension or simply throw out g. If we
allow the extension what would "d.g(c)" mean? Which operation
would it call, B's g or C's g()? We could resolve this
as in the previous item. Or maybe both should be called,
but which one FIRST? Or maybe we inherit both bodies
but require explicit qualification in the call, such
as d.B::g(c) and d.C::g(c).
- Note that there is no name clash in the inheritance of h from
B and C; d obviously has two h's that overload each other.
- Does d have two fields called x or just one?
- Does d have two methods called f or just one?
Interface Inheritance doesn't have these ambiguities
Since the methods in an interface don't have bodies, a class
implementing multiple interfaces has only one implementation
for a method even when there appears to be a name clash!
Java note: In Java you can put constants (static final
fields) in interfaces. If these clash, you need to cast
an object to an interface before using the field.