Java Interface
An interface in Java is a blueprint that defines a set of methods a class must implement without providing full implementation details.
A class must implement all abstract methods of an interface.
All variables in an interface are public, static, and final by default.
Interfaces can have default, static, and private methods.
Relationship Between Class and Interface
A class can extend another class and similarly, an interface can extend another interface. However, only a class can implement an interface and the reverse (an interface implementing a class) is not allowed.
Use case of Interface:
Use an interface when you need to define a contract for behavior that multiple classes can implement.
Interface is ideal for achieving abstraction and multiple inheritance.
implementation: To implement an interface, we use the keyword implements
Multiple Inheritance in Java Using Interface
Java does not support multiple inheritance with classes to avoid ambiguity, but it supports multiple inheritance using interfaces.

Top comments (0)