Menu

1 / 2

Java learning Series | Interface

DEV Community: java·Ajay·12 days ago
#U6WSiqae
#devtojava#devto#dev#class#interface
Reading 0:00
15s threshold

what is Interface ?

Interface is a reference type of a class that defines contract specifying methods that implementing classes must provide.

Interface only has an abstract methods (no method body).

Object cannot be created using Interface name.

Using implements it connect with the class

one class can implements with multiple interfaces.

why Interface ?

An interface in Java is used to define a strict contract of behaviors (methods) that a class must follow. It specifies what a class must do without dictating how it does it, more flexible, and scalable code

Achieving Abstraction --> An interface hides internal implementation details and exposes only the essential method signatures. because the different class can define the method in different way so , the interface declared without out body .were class declared the body with the same method name in interface.

Supporting Multiple Inheritance --> Java restricts a class from extending more than one parent class to avoid ambiguity.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.