Skip to content
Advertisement

Implementing two interfaces with two default methods of the same signature in Java 8

Suppose I have two interfaces:

JavaScript

If I want to implement both of them, what implementation will be used?

JavaScript

Advertisement

Answer

This is a compile-time error. You cannot have two implementation from two interfaces.

However, it is correct, if you implement the getGreeting method in C1:

JavaScript

I just want to add that even if the method in I1 is abstract, and default in I2, you cannot implement both of them. So this is also a compile-time error:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement