Why doesn't C# allow multiple inheritances?

Question:

In C# we can implement several interfaces. But why can't we inherit from more than one base class?

Answer:

Inheriting from many concrete classes is a big source of problems from a programming language design point of view: what if the two superclasses have a method of the same name? What if I have instance variables of the same name? A particularly tricky problem is diamond inheritance . Consider the following inheritance pattern:

  A
 / \
B   C
 \ /
  D

A is a superclass that defines a virtual method foo() . B and C are classes that inherit from A and redeploy foo . Finally, D is a class that multiple inherits from B and C. Now if we do

A obj = new D();
obj.foo();

which version of the method is called? The version defined in B or the one defined in C?

Due to these complications, many programming languages ​​(including C# and Java) prefer to keep things simple and allow only simple inheritance.

That said, it could be that the language provides alternatives to some of the more common uses of multiple inheritance. For example, C# allows a class to implement more than one Interface, which is similar to multiple inheriting from purely abstract classes.

Scroll to Top