How to create multiple inheritance inc#, with example?
Submitted by: AdministratorA class can implement multiple interfaces.
public class A : Ix, Iy,Iz
This way you can achieve multiple inheritence
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();
}
}
}
Submitted by: Administrator
public class A : Ix, Iy,Iz
This way you can achieve multiple inheritence
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();
}
}
}
Submitted by: Administrator
Read Online Microsoft.NET 2.0 Job Interview Questions And Answers
Top Microsoft.NET 2.0 Questions
☺ | Explain What is the reason of occurring overflow-underflow arithmetic exception error, it shows error message when we run our program by adding control? |
☺ | What is 2 tier and 3 tier architecture? |
☺ | Explain the procedure to add assemly to GAC to make it shared one? |
☺ | Explain What rare the Types of JIT and what is econo-JIT? |
☺ | In .NET Compact Framework, can we free memory explicitly without waiting for garbage collector to free the memory? |
Top Dot Net Technologies Categories
☺ | MSF Interview Questions. |
☺ | .Net Architecture Interview Questions. |
☺ | ASP.Net MVC Interview Questions. |
☺ | Entity Framework Interview Questions. |
☺ | C# (Sharp) Programming Language Interview Questions. |