Interfaces

Let's learn about an important topic of Java abstraction i.e. interfaces.

What is an interface?

An interface is just like a class and specifies the behavior that a class must implement.

An interface can be used to achieve 100% abstraction as it contains the method signatures/abstract methods(what to be done) and no implementation details (how to be done) of these methods. In this way, interfaces satisfy the definition of abstraction. The implementation techniques of the methods declared in an interface are totally up to to the classes implementing that interface.

An interface can be thought of as a contract that a class has to fulfill while implementing an interface. According to this contract, the class that implements an interface has to @Override all the abstract methods declared in that very interface.

Declaration

An interface is declared just like a class but using the keyword interface:

Get hands-on with 1400+ tech skills courses.