Why do we use interfaces in Java?

Java 8Object Oriented ProgrammingProgramming

An interface is a reference type in Java. It is similar to a class. It is a collection of abstract methods. A class implements AN interface, thereby inheritable the abstract ways of the interface.

An interface is a specification or a contract if a class implements an interface it indicates that class provides all the behaviors specified in that interface. In a way, it establishes communication between two objects.
Since Java does not support the concept multiple inheritance, an interface is used to achieve multiple inheritance.

raja
Published on 10-Jan-2018 17:00:39
Advertisements