Menu

1 / 2

Interface in java

DEV Community·Sakthi S·6 months ago
#6k1tVN0v
#java#webdev#software#coding#interface
Reading 0:00
15s threshold

Java Interface

An interface in Java is a blueprint that defines a set of methods a class must implement without providing full implementation details.

A class must implement all abstract methods of an interface.

All variables in an interface are public, static, and final by default.

Interfaces can have default, static, and private methods.

Relationship Between Class and Interface

A class can extend another class and similarly, an interface can extend another interface. However, only a class can implement an interface and the reverse (an interface implementing a class) is not allowed.

Use case of Interface:

Use an interface when you need to define a contract for behavior that multiple classes can implement.

Interface is ideal for achieving abstraction and multiple inheritance.

implementation: To implement an interface, we use the keyword implements

Multiple Inheritance in Java Using Interface

Java does not support multiple inheritance with classes to avoid ambiguity, but it supports multiple…

Continue reading — create a free account

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