What is an Interface in Java?

Interface: Any service requirement specifications or Any contract between client and service provider or 100 percent pure abstract class is called an interface.

  • An interface is a reference type in Java.
  • It is similar to class.
  • It is a collection of abstract methods.
  • A class implements an interface, thereby inheriting the abstract methods of the interface.
  • In an interface, each method is public and abstract but it does not contain any constructor. 
  • Interface basically is a group of related methods with empty bodies.

Syntax:

/* File name : NameOfInterface.java */
import java.lang.*;
// Any number of import statements

public interface NameOfInterface 
{
    // Any number of final, static fields
    // Any number of abstract method declarations
    public void eat();
    public void sleep();
    public void run();
}