eguruchela

What is interface?


Interface is a reference type in Java and similar to class. It is a collection of abstract methods.

A class implements an interface, thereby inheriting the abstract methods of the interface.

We can say that interface in Java is a blueprint of a class. It has static constants and abstract methods.

It is a mechanism to achieve abstraction. There can be only abstract methods in the Java interface not method body. It is used to achieve abstraction and multiple inheritance in Java.

import java.lang.*;

public interface InterfaceSample {
   // Any number of final, static fields
   // Any number of abstract method declarations\
}

👈       👉