Write code for interface implementation in C#

(Last Updated On: February 26, 2019)

Answer includes concept for interface implementation in C# with example. Also, it includes example of multiple interface implementation.

Answer: C# Interface inheritance or implementation is a simple concept object oriented programming. Let’s understand in a simple word.  We create an interface having one or more unimplemented methods in it. A class implements this interface, meaning, the class implements all methods available in the interface.

Note that a class should implement all methods from interface or else compiler will flash an error.

Here is an example program, in which class Aeroplane will inherit an interface and will implement an interface called IFlyable. Meaning, it will implement the method fly() present in IFlyable interface.

 

Example of single interface implementation in C#

 

A class can inherit or implement multiple interfaces in C# programming. Note that multiple class inheritance is not supported in C# programming. But, multiple interfaces can be inherited and implemented.

 

Example of Multiple interface implementation in C#:

In this multiple interface implementation example, we will be inheriting two interfaces and implements methods from both interfaces into class Bird.

 

 

Read another interview question – tell example scenario where C# interface is indispensable