Can an interface extend multiple interfaces in Java?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
In Java, interfaces are a pivotal part of defining contracts for classes to implement. They allow developers to specify methods that must be implemented by any class that implements the interface. A striking feature of Java interfaces is their ability to support multiple inheritance. This capability often leads to the question: Can an interface extend multiple interfaces in Java? The answer is a resounding yes.
Interfaces and Inheritance
Understanding Interfaces
Before delving into the extension of interfaces, let's briefly understand what interfaces are in Java. An interface in Java is similar to an abstract class that has all of its methods as abstract. It provides a way for classes to commit to implementing methods without actually defining any behavior.
In this Vehicle interface, any class implementing it must provide implementations for start() and stop() methods.
Single vs. Multiple Inheritance
Java does not support multiple inheritance with classes to avoid complications like the "Diamond Problem", where a class inherits from two classes that have a common ancestor. However, since interfaces do not contain any state, Java allows multiple inheritance for interfaces.
Extending Multiple Interfaces
An interface can extend multiple interfaces, thereby combining their contracts. This feature is particularly useful for creating more versatile and reusable interface hierarchies.
Here, ElectricAutonomousVehicle extends both Electric and Autonomous interfaces. Any class implementing ElectricAutonomousVehicle will need to implement methods from all three interfaces (Electric, Autonomous, and ElectricAutonomousVehicle).
Technical Implementation
To understand how this works in practice, let's look at an implementation demonstration.
In this example, TeslaModelS implements the ElectricAutonomousVehicle interface. Thus, it is obligated to provide implementations for charge(), selfDrive(), and autopilot(). Additionally, assuming it also implements the Vehicle interface, it must implement start() and stop().
Benefits and Use-Cases
- Reusability: By composing interfaces, code reuse is maximized. A class can inherit behaviors from several sources rather than being limited to a single parent class.
- Flexibility: Interfaces allow for a flexible system design. Classes can adopt multiple behaviors and thus adapt better to changing requirements.
- Separation of Concerns: Instead of a monolithic design, behaviors are neatly separated and grouped logically, promoting a cleaner architecture.
Key Differences Between Interface and Class Inheritance
- State: Interfaces do not hold state; classes do.
- Default Methods: Since Java 8, interfaces can have default methods, allowing method definitions.
- Implementation Requirements: Classes inheriting from another class can inherit method implementations directly, whereas interfaces only specify method signatures (abstract methods).
Summary Table
| Feature/Concept | Description |
| Multiple Inheritance for Classes | Not allowed to prevent ambiguity (e.g., the Diamond Problem). |
| Interface Inheritance | An interface can extend multiple interfaces. |
| Implements Keyword | Used by classes to adhere to an interface's contract. |
| Default Methods | Since Java 8, interfaces can have methods with default implementations. |
| Stateless | Interfaces cannot maintain a state. |
| Compulsory Implementation | Classes implementing an interface must provide concrete implementations. |
In conclusion, Java's ability for an interface to extend multiple interfaces is a powerful feature enabling flexible and modular design. Through strategic use of interfaces, developers can model complex systems with clean architecture and reusable code.

