Source: http://www.sitepoint.com/interface-and-inheritance-in-java-interface/
How to use:
An interface defines a contract which an implementing class must adhere to. The above interface
DriveCar defines a set of operations that must be supported by a Car. So, a class that actually implements the interface should implement all the methods declared in the interface.interface is a reference type, similar to a class, that can contain only constants, method signatures, default methods, static methods, and nested types. Method bodies exist only for default methods and static methods. Interfaces cannot be instantiated—they can only be implemented by classes or extended by other interfaces.
Example:
interface DriveCar{
interface DriveCar{
turnRight();
turnLeft();
moveBack();
accelerate();
}
class Car implements DriveCar{
void turnRight(){
//implementation code goes here
}
void turnLeft(){
//implementation code goes here
}
void moveBack(){
//implementation code goes here
}
void accelerate(){
//implementation code goes here
}
}
Now we can take a reference of type DriveCar and assign an object of Car to it.
Example:
DriveCar carDriver=new Car();
carDriver.turnLeft();
carDriver.moveBack();
//other method invocations
We can also code in the following way:
Example:
Car car=new Car();
car.turnLeft();
car.moveBack();
//other method invocations
Javapoint.comUse of interface by third user:Use of interface to satisfy multiple inheritance
Still static method will have body inside interface