Contact Us or call 1-877-932-8228


Interfaces define a standardized set of commands that a class will obey.

The commands are a set of methods that a class implements.

The interface definition states the names of the methods and their return types and argument signatures. There is no executable body for any method that is left to each class that implements the interface.

Once a class implements an interface, the Java compiler knows that an instance of the class will contain the specified set of methods. Therefore, it will allow you to call those methods for an object referenced by a variable whose type is the interface.

Implementing an interface enables a class to be "plugged in" to any situation that requires a specific behavior (manifested through the set of methods).

An analogy: a serial interface on a computer defines a set of pin/wire assignments and the control signals that will be used. Note that:

  • The actual devices that can be used may do entirely different tasks: mouse, modem, etc.
  • But they are all controlled through the same digital instruction mechanism; the individual wires are specified to carry specific signals.

Using an interface rather than inheritance to specify a certain set of methods allows a class to inherit from some other class.

  • In other words, if a class needs two different sets of methods, so it can behave like two different types of things, it could inherit one set from class A, and use an interface B to specify the other.
  • You could then reference one of these objects with either an A reference or a B reference.

Interfaces can also specify constants that are public, static, and final.