Tuesday

Interface in Java and Object Oriented Programming

An interface s similar to class. It is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface.
The interface in Java is a mechanism to achieve abstraction. There can be only abstract methods in the Java interface, not method body. It is used to achieve abstraction and multiple inheritance in Java.
Writing an interface is similar to writing a class. But a class describes the attributes and behaviors of an object. And an interface contains behaviors that a class implements.
Java Interface also represents the IS-A relationship.It cannot be instantiated just like the abstract class. Since Java 8, we can have default and static methods in an interface. Since Java 9, we can have private methods in an interface.
read more......

Why use Java interface

0 comments:

Post a Comment