Tech moves fast! Stay ahead of the curve with Techopedia!
Join nearly 200,000 subscribers who receive actionable tech insights from Techopedia.
An interface specifies a group and/or a set of methods, which have not been implemented. When a class implements an interface, the class provides an implementation to all defined interface methods. A single class may implement any number of interfaces. Sometimes, constant declarations are included in an interface, along with method definitions.
Disadvantages for the interface is that all interface methods must be public and only abstract methods may be used in an interface. However, because these methods are implicit, they are not declared.
An interface is best explained with an example. The most common example is the connections among a television, a remote control, and a user. A user turns on the TV by using the remote control and may not necessarily know anything about the TV’s wiring. Thus, the remote control is an interface between the user and the television set.
Similarly, when a class implements an interface, the method functionalities are implemented without knowledge of the method's inner workings.
The following are examples of when to use an interface:
Join nearly 200,000 subscribers who receive actionable tech insights from Techopedia.