java interfaces tutorial

java interfaces tutorial in this tutorial we will learn Benefits of using interface, a syntax of the interface, How to inherit an interface, Multiple inheritances using interface, Extending Interfaces, Extending Multiple Interfaces.

Marker interface or Tag interface, Use of marker interface, When to use interface over abstract class, Diffrace between interface and abstract class, Final methods, Final variables, Final classes,  Advantages of final keyword.


java interfaces tutorial

An interface is a blueprint of a class. It has static constants and abstract methods.

The interface is a mechanism to achieve full abstraction in Java. There can be only abstract methods in the interface. It is used to achieve full abstraction and multiple inheritances in Java.

The interface also represents IS-A relationship.

It cannot be instantiated just like an abstract class.

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:-

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