Practice mode Java

What happens if a Java class implements two unrelated interfaces that each define a default method void run() and the class does not override it?

Correct answer A. The class fails to compile

Explanation

A class that inherits override-equivalent default methods from unrelated interfaces, with no overriding declaration of its own, causes a compile-time error. Java never picks a winner by order of declaration. The fix is to override run() in the class, optionally delegating to one parent with the syntax A.super.run().

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.