Rajesh Singh
Why multiple inheritance is not possible in c#
By Rajesh Singh in .NET on Jul 09 2015
  • Pankaj  Kumar Choudhary
    Aug, 2015 26

    due to the diamond problem.

    • 3
  • Sreekanth Reddy
    Nov, 2015 2

    It causes the ambiguity error in C#.

    • 2
  • Sanjukta Pearl
    Aug, 2015 17

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

    • 2
  • Rajesh Singh
    Jul, 2015 9

    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();}

    • 2
  • Santosh Kumar
    Nov, 2015 27

    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.

    • 1
  • satheesh d
    Nov, 2021 12

    C# does not support multiple class inheritance. This is becaues of diamond problem which is associated with multiple class inheritance. For example I am having two classes namely class2 and class3 and these two classes are inherited from class1. Now we have another class namely class4 which is inherited from both class2 and class3. If the method in class4 calls a method in class1 and class 4 has not overridden the invoked method. Both class2 and clas3 has overriden the same methos differently. So there occurs the ambiguity problem wile invoking the methods. In order to solve this plobelm C# does not support multiple class inheritance.

    • 0
  • Iqrar Ali
    Dec, 2016 13

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

    • 0
  • atul gopnar
    Dec, 2015 26

    Due to Diamond problem....

    • 0
  • Sandeep Kumar
    Dec, 2015 21

    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.

    • 0
  • Sandeep Kumar
    Dec, 2015 18

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

    • 0
  • Mahesh Gawhane
    Dec, 2015 3

    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};

    • 0
  • Santosh Kumar
    Nov, 2015 27

    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.

    • 0
  • Dhanik Sahni
    Nov, 2015 17

    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?

    • 0
  • Dhanik Sahni
    Nov, 2015 17

    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?

    • 0
  • Sreekanth Reddy
    Nov, 2015 2

    It causes the ambiguity error in C#.

    • 0
  • Francis
    Oct, 2015 26

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

    • 0
  • Ashok Reddy
    Oct, 2015 8

    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.

    • 0
  • Bhushan Bhasme
    Oct, 2015 4

    Due To Diamond Problem...

    • 0
  • Sujeet Suman
    Sep, 2015 2

    Due to diamond problem.

    • 0
  • Dimple Sharma
    Aug, 2015 10

    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.

    • 0
  • Swapnil Mache
    Aug, 2015 7

    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.

    • 0
  • Munesh Sharma
    Aug, 2015 5

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

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS