Question:
How can create multiple inheritence inc#, with example?
Answer:
A class can implement multiple interfaces.
public class A : Ix, Iy,Iz
This way you can achieve multiple inheritence Source: CoolInterview.com
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(); } } } Source: CoolInterview.com
Answered by: Asha Sivan | Date: 6/25/2009
| Contact Asha Sivan
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|