Why multiple inheritance is not supported in c#?
Answers (1)
Add AnswerSuppose the inheritance is possible in c#
public class A { public virtual void Method_A() { Console.WriteLine("Class A Method"); } } public class B : A { public override void Method_A() { Console.WriteLine("Class B Method"); } } public class C : A { public override void Method_A() { Console.WriteLine("Class C Method"); } } public class D : B, C { public override void Method_A() { Console.WriteLine("Class C Method"); } } public static void main() { D objD = new D(); objD.Method_A(); }
When an object of class D calls the overloaded method Method_A will confuse the compiler on which class method to call as both inherited class methods have been overloaded.
It is called the Diamond problem.
So there occurs the ambiguity problem while invoking the methods. To solve this problem, C# does not support multiple inheritances.