Start Coding Now

Interfaces in Java - Multiple Inheritance

Learn about interfaces in Java. How to achieve multiple inheritance and loose coupling using interface keyword.

Interfaces

An interface is a completely "abstract class" that is used to group related methods with empty bodies.

Key Points:

  • Use interface keyword.
  • Methods are by default abstract and public.
  • Attributes are by default public, static, and final.
  • A class implements an interface.
interface Animal {
  public void animalSound(); // interface method (does not have a body)
  public void sleep(); // interface method (does not have a body)
}

class Pig implements Animal { public void animalSound() { System.out.println("The pig says: wee wee"); } public void sleep() { System.out.println("Zzz"); } }

Frequently Asked Questions