Interface in Java
Interface in Java
Interface is the way to achieve pure abstraction, Same like class Interface can have variables (by default public, static and final) and methods(by default abstract and public). Before Java 1.8 we can only declare the methods in interface. It can be call as blueprint of the Class.
Interface doesn’t provide method definition, It has to be override by the class which will be using this interface. Class can use interface using implements keyword. Interface can use another interface using extends keyword. If any class is implementing any interface then method definition must be given else need to define this class as abstract and some other class will be extending this class to give definition for the same.
interface nameOfInterface { // declare constant and methods }
Below is the sample program for the same
Click Here-> Get Prepared for Java Interviews
New features added in interfaces in Java 1.8
We can give the definition of method or can give implementation for interface methods. Below is the example for the same.
Another one more way
Click Here-> Get 100% Practical Java Training