Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

Java Interface Extends Another Interface: Syntax & Use Cases

Learn how a Java interface can extend another interface, combine multiple interfaces, and use default methods and constants with practical Java code examples.

~4 min readJava
#Java#Interfaces#Inheritance#Type Hierarchy
Diagram showing a Java interface extending another interface with default methods and constants.

In Java, an interface can extend one or more other interfaces using the extends keyword. The child interface inherits abstract methods, default methods, and constants from its parents and is a subtype of each parent. A class implementing the child must satisfy the combined contract: abstract methods are normally implemented by the class, except where an inherited default method already supplies an implementation. This is distinct from a class implementing an interface directly.

The Syntax for Extending an Interface

The syntax is similar to class inheritance but uses extends and allows multiple parents:

java
public interface Readable { String read(); } public interface Writable { void write(String data); } public interface ReadWritable extends Readable, Writable { // inherits read() and write() }

Here, ReadWritable extends both Readable and Writable. A class that implements ReadWritable must provide concrete implementations for read() and write(). You can also extend a single interface:

java
public interface ExtendedReadable extends Readable { String readLine(); }

The ExtendedReadable interface adds a new method while inheriting read(). Classes implementing ExtendedReadable must implement both methods.

Why Extend an Interface Instead of Implementing It?

When one interface extends another, the child interface becomes a more specialized contract. This is useful when you want to express that a particular capability is a refinement of a broader one. For example, List extends Collection, adding positional access methods. By extending, you avoid repeating method signatures and establish a clear subtype relationship that the compiler enforces.

Extending an interface is not the same as implementing it. A class implements an interface to provide behavior; an interface extends another to inherit and extend its contract. The child may add methods and may provide default implementations, but any inherited abstract method that it does not satisfy remains part of the contract. This distinction matters when designing APIs: you can create a hierarchy of interfaces that represent increasing levels of capability without forcing concrete implementation details into every layer.

Extending Multiple Interfaces

Java interfaces support multiple inheritance of type: a single interface can extend several parent interfaces. This is a key difference from classes, which cannot extend more than one superclass. It is safe because interfaces do not carry instance state, so there is no state-combination problem. For example:

java
public interface Trackable { // marker } public interface Loggable { void log(String message); } public interface Persistable extends Trackable, Loggable { void save(); }

A class implementing Persistable must implement log() and save(), and it is automatically considered a Trackable and Loggable because of the subtype relationship. This lets you compose capabilities from multiple sources. Default-method conflicts are still possible, however, and must be resolved explicitly.

Default Methods in Extended Interfaces

Since Java 8, interfaces can include default methods with a body. When an interface extends another that has a default method, the child inherits the implementation unless it overrides it or redeclares the method as abstract. If the child declares an otherwise inherited default method as abstract, implementing classes must provide their own implementation.

Consider:

java
public interface Greeter { default String greet() { return "Hello"; } } public interface FriendlyGreeter extends Greeter { @Override default String greet() { return "Hi there"; } }

Here, FriendlyGreeter overrides the default method. If a child interface extends two unrelated parents that both declare the same default method, the compiler will reject it unless the child explicitly resolves the conflict.

Constants and Static Members in Interface Hierarchies

Interfaces can declare constants (static final fields). When an interface extends another, constants from the parent interfaces are inherited and can be referenced through the child interface name. If two parent interfaces declare a constant with the same name, you must qualify it with the parent interface name to avoid a compile-time conflict.

Static methods in interfaces are not inherited by implementing classes. They are not part of the instance contract, and they must be called through the interface that declares them. A child interface that needs a parent's static method should call it as ParentInterface.method().

Common Mistakes and Ambiguity Resolution

One common mistake is assuming that an interface extending another automatically provides implementations for all inherited methods. That is only true for default methods. Abstract methods that are not otherwise satisfied remain abstract, and the implementing class must supply their bodies.

Another issue arises when an interface extends multiple parents that declare methods with the same signature but incompatible return types. Java does not allow a method to be overloaded by return type alone, so the compiler will report a conflict. You must refactor the hierarchy to avoid such clashes.

When default methods conflict, you must override the method in the child interface and explicitly choose which parent's implementation to call using the InterfaceName.super.method() syntax. For example:

java
public interface A { default void action() { System.out.println("A"); } } public interface B { default void action() { System.out.println("B"); } } public interface C extends A, B { @Override default void action() { A.super.action(); } }

This resolves the ambiguity and gives you explicit control over the inherited behavior.

Maintainability and Design Considerations

Interface hierarchies are a powerful tool, but they can become unwieldy if overused. Deep inheritance chains make it harder to understand which methods are actually available on a given interface. Prefer shallow hierarchies and favor composition of interfaces over deep inheritance. When you design an interface that extends another, ask whether the child truly represents a subtype of the parent. If the child only reuses a few methods, consider whether a separate interface or a default method would be simpler.

Also, be mindful of the sealed interface feature introduced in Java 17. A sealed interface restricts which interfaces or classes can implement or extend it. This can make the hierarchy more predictable and improve maintainability by limiting the set of subtypes. However, it also reduces extensibility, so use it only when you control the entire hierarchy.

Finally, remember that interfaces are contracts. Extending an interface should communicate a clear relationship between capabilities. Overly complex hierarchies can make code harder to navigate and test. Keep the hierarchy as flat as possible, and use default methods to provide common behavior without forcing every implementer to duplicate logic.

Try matching browser tools

All tools

Small utilities that fit Java work — they run entirely in this browser tab, so nothing you paste leaves your device.

All Java guides

More in Java

All Java guides

The guides filed next to this one in Java, in library order.