Pages

Men

rh

4/02/2013

How can create multiple inheritance inc#, with example?


In C#, a class cannot have multiple inheritance with classes. But class can have multiple inheritance with one class and more than one interface.

Eg: 

namespace TestClass
{
public class A
{
public void testA()
{
Console.WriteLine("In Class A");
}
}
interface IB
{
void testIB();
}
interface IC
{
void testIC();
}

public class Test : A, IB, IC
{
public void testIB()
{
Console.WriteLine("In Interface IB");
}
public void testIC()
{
Console.WriteLine("In Interface IC");
}
}
class Program
{
static void Main(string[] args)
{

Test tt = new Test();
tt.testA();
tt.testIB();
tt.testIC();
Console.ReadLine();
}
}
}

No comments :

Post a Comment