what is Interface ?

Interface is a reference type of a class that defines contract specifying methods that implementing classes must provide.

  • Interface only has an abstract methods (no method body).
  • Object cannot be created using Interface name.
  • Using implements it connect with the class
  • one class can implements with multiple interfaces.

why Interface ?

An interface in Java is used to define a strict contract of behaviors (methods) that a class must follow. It specifies what a class must do without dictating how it does it, more flexible, and scalable code

  • Achieving Abstraction --> An interface hides internal implementation details and exposes only the essential method signatures. because the different class can define the method in different way so , the interface declared without out body .were class declared the body with the same method name in interface.

  • Supporting Multiple Inheritance --> Java restricts a class from extending more than one parent class to avoid ambiguity. However, a single class can implement multiple interfaces at the same time, allowing it to inherit behaviors from several sources.

For example :

interFace

Employee Class