Can We Override Default Method in Java?

Last Updated : 11 Sep, 2026

A default method in Java is a method declared inside an interface using the default keyword and having a method body. It allows interfaces to provide a default implementation that implementing classes can either use directly or override.

  • Default methods were introduced in Java 8 to allow interfaces to evolve without breaking existing implementing classes.
  • An implementing class automatically inherits a default method unless it provides its own implementation.
  • If multiple interfaces provide conflicting default methods, the implementing class must resolve the conflict.

Syntax of a Default Method

A default method is declared using the default keyword followed by the return type, method name, and method body.

interface InterfaceName {
default void methodName() {
// Default implementation
}
}

Note: Default methods can only be declared inside interfaces. They are implicitly public and cannot be declared abstract.

Override a Default Method

Yes, a default method can be overridden by an implementing class. However, overriding is optional when there is no conflict. If the class does not override the method, it uses the implementation provided by the interface.

Consider the following example where the class directly uses an inherited default method:

Java
interface Message {

    default void display() {
        System.out.println("Default method from interface");
    }
}

public class GFG implements Message {

    public static void main(String[] args) {

        GFG obj = new GFG();

        obj.display();
    }
}

Output
Default method from interface

Explanation: The Message interface provides the implementation of display(). Since GFG does not override the method, the default implementation is inherited and called through the GFG object.

Overriding a Default Method in Java

A class can override a default method when it needs behavior different from the implementation provided by the interface.


Output
Overridden method in class

Explanation: GFG overrides the display() method and provides its own implementation. Therefore, when obj.display() is called, the implementation defined in GFG is executed instead of the interface's default implementation.

When Is Overriding a Default Method Required?

Overriding is generally optional, but it becomes necessary when a class implements multiple interfaces that provide conflicting default methods with the same signature.

For example, the following code causes a compile-time error:

Java
interface A {

    default void show() {
        System.out.println("Default method from A");
    }
}

class B implements A {

    public static void main(String[] args) {

        B obj = new B();

        obj.show();
    }
}

Output
Default method from A

Explanation: Class C provides its own implementation of show(). This removes the ambiguity between the default methods inherited from A and B.

Calling a Specific Interface's Default Method

Instead of completely replacing the interface implementations, a class can explicitly call a particular interface's default method using:

InterfaceName.super.methodName();

Java
interface A {

    default void show() {
        System.out.println("Default method from A");
    }
}

interface B {

    default void show() {
        System.out.println("Default method from B");
    }
}

class C implements A, B {

    @Override
    public void show() {
        A.super.show();
        B.super.show();
    }

    public static void main(String[] args) {

        C obj = new C();

        obj.show();
    }
}

Output
Default method from A
Default method from B

Explanation: A.super.show() calls the default implementation of show() from interface A, while B.super.show() calls the implementation from interface B. The class overrides show() to explicitly choose how both interface implementations should be used.

Rules for Default Methods

The important rules for default methods are:

  • A default method must be declared inside an interface using the default keyword.
  • An implementing class is not required to override a default method unless a conflict needs to be resolved.
  • If a class defines a method with the same signature as an interface's default method, the class implementation takes precedence.
  • If two unrelated interfaces provide the same default method, the implementing class must override it.
  • A specific interface's implementation can be invoked using InterfaceName.super.methodName().
  • Default methods cannot override methods of the Object class such as equals(), hashCode(), or toString() with a default implementation.
Comment