What is an interface class? Explain with example.
540
29-Nov-2021
Home / DeveloperSection / Interviews / What is an interface class? Explain with example.
Sanjay Goenka
02-Sep-2022An interface is a reference type in Java. It is similar to class. It is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface.
Along with abstract methods, an interface may also contain constants, default methods, static methods, and nested types. Method bodies exist only for default methods and static methods.
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.
Unless the class that implements the interface is abstract, all the methods of the interface need to be defined in the class.
An interface is similar to a class in the following ways −
Ravi Vishwakarma
29-Nov-2021