Java: Implementing Interfaces with Default Methods

Wednesday May 12th 2021 by MS Sridhar
Article Image

We discuss how to implement interfaces with default methods in this Java developer tutorial. Read more.

In the sample code below, you will find some samples code showing how to implement an interface with a default method using Java. Note that there are cases in which multiple interfaces will have the same default method. Feel free to explore those instances on your own and come back here for a future update.

In addition to implementing interface with default methods, you can also try commenting out the the print method in the Impl class and observe the difference in behavior of the call flow to the print method.


public class DefaultMethodInterfaceImpl implements DefaultMethodInterface {

	public static void main(String args[])
		DefaultMethodInterfaceImpl defaultMethodInterfaceImpl = new DefaultMethodInterfaceImpl();

	public void print() {
		System.out.println("In print of Impl.");



$java DefaultMethodInterfaceImpl
In print of Impl.
I am the default method in the interface!
Mobile Site | Full Site