What is an interface class?

0 votes
128 views
Shikhar Arora asked 06-Dec-2019 in Technology by Shikhar Arora

What is an interface class

1 Answer

0 votes
Rahul Roi answered 29 days ago by Rahul Roi

What is an interface class?

An interface (in C#) is a blueprint of a class. This is like abstract class because all the methods which are declared inside the interface are abstract methods. Interface cannot have method body and cannot be instantiated.

This is used to achieve multiple inheritance which can't be achieved by class. This is used to achieve fully abstraction because it cannot have method body.
That's implementation must be provided by class or struct. By the way, the class or struct which implements the interface, must provide the implementation of all the methods declared inside the interface.
  • The Interfaces specify what a class must do and not how.
  • The Interfaces can’t have private members.
  • By default all the members of Interface are public and abstract.
  • The interface will always defined with the help of keyword ‘interface‘.
  • The Interface cannot contain fields because they represent a particular implementation of data.
  • The Multiple inheritance is possible with the help of Interfaces but not with classes.

Advantage of Interface:

  • This is used to achieve loose coupling.
  • This is used to achieve total abstraction.
  • To achieve component-based programming
  • To achieve multiple inheritance and abstraction.
  • The Interfaces add a plug and play like architecture into applications.