DEV Community

Divya Divya
Divya Divya

Posted on

Interface in java?

Interface
An interface in Java is a blueprint of a class.
It contains methods that a class must implement.

Interface mainly helps to achieve:

Abstraction → hiding implementation details
Multiple inheritance → one class can implement multiple interfaces.

A class uses the implements keyword to implement an interface.
All methods inside an interface are public and abstract by default.
Variables inside an interface are automatically:

  • public
  • static
  • final

Syntax

interface Animal {

    void sound();   // abstract method
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)