Interviews2 answers
2 Answers
Multiple inheritance is not supported in C# through classes because
Class P1
{
public void func1()
{
.....;
}
}
Class P2
{
public void func1()
{
....;
}
}
Class P3:P1,P2
{
static void Main()
{
P3 obj=new P3();
P3.func1();//Here runtime gets confused whether to call func1() of ClassP1 orP2; Ambuguity
}
}
Hence Multiple inheritance is possible using interfaces
Chetnaa DesaiPosted Aug 27, 2015, 9:57 PM EDT
When we use the Multiple inherutance we use more than one class. Lets one condition class A and class B are base classes and class c is is multiple inherting it.And where class c is inheriting a function .It may be possible that this function with same name and same signature can present in both class A and Class B . That time how the compiler will know that which function it should take wherether from class A or class B.So Multiple inheritance show's an error.
Sapna MalikPosted Sep 6, 2009, 10:48 PM EDT
