Home / Questions / What is an Interface?
Explanatory Question

What is an Interface?

👁 700 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation

An interface is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface.

In Java, an interface is a blueprint of a class that contains only abstract methods (methods without a body) and constant fields. An interface is used to define a common behavior for multiple classes, allowing them to work together. Interfaces provide a way to achieve abstraction in Java and are used to define a contract that must be implemented by concrete classes. By implementing an interface, a class agrees to perform the behavior specified in the interface. Interfaces can also be extended by other interfaces, making it possible to define a hierarchy of behaviors.