Interfaces


Like a class, an interface can have methods and variables, but the methods declared in interface are by default abstract (only method signature, no body).
The syntax for declaring an interface is given on the right:
interface <interface_name> {
  // Declare constant fields.
  // Declare methods that are abstract by default.
}

To declare an interface, use interface keyword. It is used to provide total abstraction. That means all the methods in interface are declared with empty body and are public and all fields are public, static, and final by default. A class that implements interface must implement all the methods declared in the interface. To implement interface use implements keyword.