You must Sign In to post a response.
  • Category: .NET

    Why multiple Inheritance is not possible in C#?

    Hai all,

    C++ can support multiple inheritance than why not c# oR vb.net?
    Then how it was working fine in C++??
    how interface overcome multiple inheritance ?
    Which reasons they omited multiple inheritance?
  • #742921
    Multiple inheritance is mainly discouraged to avoid the Classic diamond problem which is explained in the following links.

    http://en.wikipedia.org/wiki/Diamond_problem

    http://social.msdn.microsoft.com/Forums/en-US/01a995ea-9e06-4fa4-bdbb-682243f386a8/why-multiple-inheritance-of-classes-in-not-supported-in-c

    http://blogs.msdn.com/b/csharpfaq/archive/2004/03/07/why-doesn-t-c-support-multiple-inheritance.aspx

  • #742963
    To avoid the DIAMON issue the multiple inheritance is not allowed in c#.


    In .net multiple inheritance comes with a major issue that is called the Diamond Issue. diamond problem is an ambiguity that arises when two classes B and C inherit from A, and class D inherits from both B and C. If 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?

    A

    B---A

    C--A

    D---B,C

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #742991
    Hi,

    For ex, in classA you have one method name as "xyz" and in classB also you have a method name as "xyz". When you try to multiple inheritance then CLR gets confused which base class method that is, that's the reason C#.net won't support multiple Inheritance.

    Hope this will help you...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #743011
    In dot net we used multiple interfaces. dot net doesn't support multiple inheritance.

  • #743199
    Hi Srinivasan,

    C# supports single, hierarchical and multilevel inheritance because there is only a single base class.

    C# does not support multiple inheritance directly because there are multiple base classes. We can achieve it using interfaces.

    -----------------------------------------------------------------------------
    Regards,
    Gopi A.
    +91 9894315571
    Skype:gopi.net
    http://asaigopi-dotnet.blogspot.in/


  • Sign In to post your comments