Multiple interfaces implementation C Sharp program example

Multiple interfaces implementation C# program example – In C#, a class can extend only one parent class so multiple inheritance(extends) is not possible but a class can implement multiple interface so using of multiple inheritances are not possible in C# but multiple implementation of interfaces are possible.

 

C# program on multiple interfaces:

//Multiple interfaces implementation C# program example

 
interface A {
	void displayOne();
 
}
 
interface B {
	void displayTwo();
}
 
interface C {
	void displayThree();
}
 
class Derive : A, B, C {
 
	
	public void displayThree() {
		Console.WriteLine("DisplayOne method is implemented: ");
 
	}
 
	
	public void displayTwo() {
		Console.WriteLine("DisplayTwo method is implemented: ");
 
	}
 
	
	public void displayOne() {
        Console.WriteLine("DisplayOne method is implememted: ");
 
	}
 
}
 
public class TestMultipleInterface {
 
	public static void Main(String[] args) {
 
		Derive dr = new Derive();
		dr.displayOne();
		dr.displayTwo();
		dr.displayThree();
 
	}
 
}

Output:
DisplayOne method is implememted:
DisplayTwo method is implemented:
DisplayOne method is implemented:

Related Posts