Interfaces specify what a class must do and not how. It’s a way to achieve abstraction in Java.
Source Code
interface Animal {
public void animalSound(); // interface method (does not have a body)
public void run(); // interface method (does not have a body)
}
class Pig implements Animal {
public void animalSound() {
// The body of animalSound() is provided here
System.out.println("The pig says: wee wee");
}
public void run() {
// The body of run() is provided here
System.out.println("The pig runs");
}
}