What is interface in Java?Why are used?



Ayush Said

+0 -0

An interface is a collection of abstract methods (methods without a body) that define a contract for a class to implement. An interface is defined using the "interface" keyword.
A class that implements an interface must provide an implementation for all of the methods defined in the interface. This is achieved by using the "implements" keyword.
Interfaces are used to define a contract for a class, ensuring that the class implements a set of methods with a specific signature, and it also allows for multiple inheritance and promotes code reusability.



Submit Your Response