Interfaces

This lesson discusses interfaces, their implementation as well as multiple interfaces in detail

Implementing an interface

An interface is used to enforce the presence of a method in any class that ‘implements’ it.

The interface is defined with the keyword interface and a class can ‘implement’ it by adding : InterfaceName after the class name.

A class can implement multiple interfaces by separating each interface with a comma like : InterfaceName, ISecondInterface.

Implementing an interface is simply done by inheriting off it and defining all the methods and properties declared by the interface after that.

Example

Let’s take a look at an example exhibiting an interface.

Get hands-on with 1200+ tech skills courses.