Oct 27, 2015

Why multiple inheritance is not possible in c#

Because when two classes B and C inherit from A, and class D inherits from both B and C. If a method in D calls a method defined in A (and does not override it), and B and C have overridden that method differently, then via which class does it inherit: B, or C? So., multiple inheritance is not possible in C#. that is called Diamond Problem. But., in C# we can solve the Diamond problem with the help of interfaces in some cases.


If multiple inheritance would have allowed in the C#, there would be a problem so called "Diamond Problem". Diamond problem occurs when same method exist in two or more base classes. Thus the child class would end up inheriting duplicate methods.


No comments:

Post a Comment