Interfaces
We have discussed how an abstract class can come up with common and abstract methods. In an abstract class, we keep the methods abstract that should be different in derived classes. What if we want a full set of abstract functionalities? Or, what if we want to settle a standard of functionality? Maybe we want to establish a standard set of methods to communicate with the object? This is why we need an interface. An interface groups similar abstract methods so that it can express an abstract feature and different classes that need that feature can implement the interface. For example, the Flight
feature is implemented by Birds
and Aeroplanes
. Hence, the Flight
interface has to be fully abstract so that Birds
and Aeroplanes
can implement completely different flight techniques.
An interface can be similar to a class without the class
keyword and without all the method's body. Therefore, an interface is a collection of method signatures to be implemented like the following...