Why C# does not support multiple class inheritance

Q : Why C# does not support multiple class inheritance?
or
What are the problems of multiple class inheritance?

Ans : C# does not support multiple class inheritance because of the diamond problem that is associated, with multiple class inheritance. Let us understand the diamond problem of multiple class inheritance with an example.


   Class

As shown in the image above:
1. I have 2 classes - ClassB and ClassC
2.Both of these classes inherit from ClassA
3. Now, we have another class, ClassD which inherits from both ClassB and ClassC

So, if a method in ClassD calls a method defined in ClassA and ClassD has not overriden the invoked method. But both ClassB and ClassC have overridden the same method differently. Now, the ambiguity is, from which class does, ClassD inherit the invoked method: ClassB, or ClassC?

In order not to have these problems, C# does not support multiple class inheritance.

  « Previous    | Next »
     
Leave a Reply
Name (required)
Email (will not be published) (required)
Web Site

List of Top Hospitals in India