Qus:    Do we have multiple inheritance in .NET? Why?
Oct 12, 2020 09:17 2 Answers Views: 103 ANANYA

 



Multiple inheritance is not supported by .NET using classes and to understand that you need to understand the Diamond problem first:



The Diamond problem is an ambiguity that arises when two classes B and C inherit from Class 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 the method), and B and C have overridden that method differently, then from which class does it inherit: B or C?



So, the solution is to use interfaces for multiple inheritance.

Prev Next
Answers (2)
PADMAKEECHU Oct 13, 2020 01:48
Answer:   No, .NET supports only single inheritance due to the diamond problem. Also, it would add complexity when used in different languages. However, multiple interfaces can solve the purpose.

PARTH Oct 13, 2020 07:23
Answer:   Multiple inheritance is not supported by .NET using classes and to understand that you need to understand the Diamond problem first:

The Diamond problem is an ambiguity that arises when two classes B and C inherit from Class 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 the method), and B and C have overridden that method differently, then from which class does it inherit: B or C?

So, the solution is to use interfaces for multiple inheritance.

Post Your Answer
Guest User

Not sure what course is right for you?

Choose the right course for you.
Get the help of our experts and find a course that best suits your needs.


Let`s Connect