views:

120

answers:

5

I'm confused about an OOP feature, multiple inheritance. Does OOP allow Multiple Inheritance? Is Multiple Inheritance a feature of OOP? If Multiple Inheritance is a feature then why don't languages like C#, VB.NET, java etc. support multiple inheritance? But those languages are considered as strongly supported OOP language. Can anyone address this question?

+2  A: 

There is no requirement in OO to support multiple inheritance, which is supported by languages such as C++. C# and Java don't support and they are no less OO because of that.

Otávio Décio
Recently i came across with question " Is Multiple Inheritance is a feature of OOPS"?.
A: 

Multiple inheritance refers to a feature of SOME object-oriented programming languages, not all of them.

These other languages you are referring to use interfaces.

Francisco Soto
+2  A: 

Please take a look at Diamond Problem

Srinivas Reddy Thatiparthy
+1  A: 

Inheritance doesn't have anything to do with object orientation. There's plenty of OO languages that do not support inheritance at all and there's plety of non-OO languages that do support inheritance. Those two things are completely orthogonal.

Jörg W Mittag
Why are people downvoting this? It happens to be correct (at least vis-a-vis OO languages without inheritance). JavaScript is OO and doesn't have inheritance. And Self. And Io. And CECIL, if memory serves. And while I can't think of a non-OO language that has inheritance (Modula-2, perhaps, through careful use of its IMPORT and EXPORT statements?) this doesn't mean they don't exist.
JUST MY correct OPINION
@JUST MY correct OPINION: Haskell type classes have inheritance. They also have runtime polymorpism which is another trait that is often wrongly attributed exclusively to OO languages.
Jörg W Mittag
Ah, right! I'd forgotten about Haskell's approach. So whoever did the downvote is doubly ignorant.
JUST MY correct OPINION
A: 

First, you have to distinguish between multiple inheritance and multiple supertypes, these are two very different things.

Multiple inheritance usually reflects to an actual inheriting of implementation (like class inheritance in most OOP languages) and presents a variety of concerns. One is conflict between names and implementations (e.g., two methods with same name and a different implementation), and then issues like the idamond problem.

Multiple supertypes usually refers to the ability to check types (and in some cases cast), and usually does not involve inheriting implementations. For example, in Java you have interfaces that merely declare your methods. So your subtype supports the union of the method supported by the supertypes. This presents less problems because you do not have a method with multiple implementations.

Multiple inheritance usually involves multiple supertypes, though some languages like C++ allow you modify the visibility of this fact (e.g., who can know that type B is a subtype of type A).

To the best of my knowledge, there is no requirement for an OOP language to support either, but at least multiple-supertypes is necessary for a usable OOP language where most design patterns can be implemented in a straightforward way. Multiple inheritance, IMHO, is really not that useful to justify the complexity and costs. I've made the switch to Java ten years ago and can't say that I missed it too much.

Uri