Multiple interfaces – C Sharp example

Multiple interfaces C# example – A class can implement multiple interfaces in C# program.

In below program example, there are two interfaces Flyable and Eatable. There is a class Bird, that will implement both interfaces and override and implement methods fly and eat from both interfaces.

Implementation of Multiple interfaces C# example

 /*
 * Implementation of multiple interfaces java example
 */
 
interface Flyable {
	void fly();
}
 
interface Eatable {
	void eat();
}
 
// Bird class will implement both interfaces
class Bird : Flyable, Eatable {
 
	public void fly() {
        Console.WriteLine("Bird flying");
	}
 
	public void eat() {
        Console.WriteLine("Bird eats");
	}
	// It can have more own methods.
}
 
/*
 * Test multiple interfaces example
 */
public class Sample {
 
	public static void Main(String[] args) {
 
		Bird b = new Bird();
		b.eat();
		b.fly();
	}
 
}

Output:
Bird eats
Bird flying

Related Posts