A colleague and I are having a bit of an argument over multiple inheritance. I\'m saying it\'s not supported and he\'s saying it is. So, I thought that I\'d ask the brainy
You can't inherit multiple classes at a time. But there is an options to do that by the help of interface. See below code
interface IA
{
void PrintIA();
}
class A:IA
{
public void PrintIA()
{
Console.WriteLine("PrintA method in Base Class A");
}
}
interface IB
{
void PrintIB();
}
class B : IB
{
public void PrintIB()
{
Console.WriteLine("PrintB method in Base Class B");
}
}
public class AB: IA, IB
{
A a = new A();
B b = new B();
public void PrintIA()
{
a.PrintIA();
}
public void PrintIB()
{
b.PrintIB();
}
}
you can call them as below
AB ab = new AB();
ab.PrintIA();
ab.PrintIB();