Learn Java
import com.learnjava.oopadvanced.DefaultStaticInterfaceMethods;

Default & Static Interface Methods in Java

@Concept

Since Java 8, an interface can include default methods — declared with the default keyword and a real method body right inside the interface — giving implementing classes a ready-made implementation they can use as-is or override if they need different behavior. This solved a genuine backward-compatibility problem: before default methods existed, adding any new method to an already-published interface would break every existing class that implemented it, since each would suddenly be missing a required implementation. A default method can be added without breaking anything, since implementing classes simply inherit it automatically.

An interface can also declare static methods, which belong to the interface itself rather than to any implementing class, called through the interface's own name, like Comparator.naturalOrder(), and cannot be overridden by implementing classes at all.

@HowItWorks
1

Declaring a default method

The default keyword plus a real method body, written directly inside the interface itself.

2

Implementing classes inherit it automatically

With no obligation to override it, though they still can if different behavior is needed.

3

Why default methods exist

Adding an ordinary abstract method to an already-published interface would break every existing implementing class; a default method doesn't.

4

Overriding a default method

An implementing class can still supply its own version, which then takes priority over the interface's default one for that class.

5

Static interface methods

Belong to the interface itself, called through its name, and can never be overridden by an implementing class.

@Example
interface Greeter {
default void greet() {
System.out.println("Hello from the default method");
}
}
 
public class CustomGreeter implements Greeter {
public static void main(String[] args) {
CustomGreeter c = new CustomGreeter();
c.greet();
}
}
Output
Hello from the default method
1Greeter declares greet() as a default method, with a complete, real implementation right inside the interface.
2CustomGreeter implements Greeter but never overrides greet() itself.
3c.greet() therefore runs the interface's own default implementation automatically, with no override needed.
4The single println call inside that default method prints the one line of output.
@UseCases
Adding a new method to a widely-implemented interface without breaking existing implementing classes
Providing a sensible default behavior implementing classes can use as-is or override when needed
Calling a utility method through an interface's own name, like Comparator.naturalOrder()
Understanding why a default method, unlike a static one, can still be overridden by an implementing class

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in Java yourself — building beats watching.