21
Reply

Why multiple inheritance is not possible in c#

Rajesh Singh

Rajesh Singh

Jul 09, 2015
4.4k
1

    It causes the ambiguity error in C#.

    Srikanth Reddy
    November 02, 2015
    2

    due to the diamond problem.

    Pankaj Kumar Choudhary
    August 26, 2015
    2

    C# compiler is designed not to support multiple inheritence because it causes ambiguity of methods from different base class.

    Sanjukta Pearl
    August 17, 2015
    2

    Basically it is due to Diamond Problem. example expalined below:public class A {public virtual void A_Method(){Console.WriteLine("Class A Method");} }public class B:A {public override void A_Method(){Console.WriteLine("Class B Method");} }public class C:A {public override void A_Method(){Console.WriteLine("Class C Method");} } public class D:B,C // If Multiple inheritence is possible in C# then {public override void A_Method(){Console.WriteLine("Class C Method");} }public static void main() { D objD = new D(); objD.A_Method();// Making object of class D and calling overloaded method A_method will confuse the compiler which class method to call as both inherited class methods has been overloaded. } It is called Diamond problem because of the structure it makes while inheriting the classes as below:Class A(Base Class)Class B(Inherits A) Class C(Inherits A)Class D(Inherits B, C)public class D : IA,IB // Multiple interfaces can be implemented but it will show only one methhods after inheriting for implementation{public void Show(){throw new NotImplementedException();}}interface IA{void Show();}interface IB{void Show();}

    Rajesh Singh
    July 09, 2015
    2

    This is Cause by diamond Shape problems of two classes If 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.

    santosh kumar
    November 27, 2015
    1

    http://www.c-sharpcorner.com/article/diamond-problem-in-c-sharp/

    Iqrar Ali
    December 13, 2016
    0

    Due to Diamond problem....

    atul gopnar
    December 26, 2015
    0

    Multiple inheritance does not get implemented in C# because of Diamond drawback.If it is required to implement multiple inheritance in C# then we use at least one Interface as base class.

    Sandeep Kumar
    December 21, 2015
    0

    Multiple inheritance is possible in c# while we will use atleast one base class as interface .

    Sandeep Kumar
    December 18, 2015
    0

    ambiguity issue....Class A{Public void show () { console.writeline("Show from class A"); } }Class B{Public void show (){console.writeline("show method from class b");}}Class C: class A, class B{ // which method call here..... //class A have a show method and class b have also same method so ambiguity problem is here};

    Mahesh Gawhane
    December 03, 2015
    0

    This is Cause by diamond Shape problems of two classes If 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.

    santosh kumar
    November 27, 2015
    0

    Yes, it is due to the diamond problem.The 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 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?

    Dhanik Sahni
    November 17, 2015
    0

    Yes, due to diamond problem.The 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 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?

    Dhanik Sahni
    November 17, 2015
    0

    It causes the ambiguity error in C#.

    Srikanth Reddy
    November 02, 2015
    0

    Simply, it will increase the complexity (the developer may difficult to find which method is from which class).

    Francis
    October 26, 2015
    0

    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.

    Ashok Reddy
    October 08, 2015
    0

    Due To Diamond Problem...

    Bhushan Bhasme
    October 04, 2015
    0

    Due to diamond problem.

    Sujeet Suman
    September 02, 2015
    0

    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.

    Dimple Sharma
    August 10, 2015
    0

    Multiple inheritance is not possible beacuse Multiple inheritance Suffer From Ambugity Problem,that means there can be chances that same method present in both the call.

    Swapnil Mache
    August 07, 2015
    0

    http://net-informations.com/faq/general/inheritance.htm

    Munesh Sharma
    August 05, 2015
    0