Page 1 of 1

About Question enthuware.ocpjp.ii.v11.2.3374 :

Posted: Thu Nov 07, 2019 5:29 am
by Artuwok
Hi, Paul. Is correct answer here is "@Override can only be used on instance methods."

But is this right? What about default methods in interfaces? They are not instance methods as far as i understand.

Code: Select all

public interface A {
    default void x() {}
}

Code: Select all

public interface B extends A {
    @Override
    default void x() {
        
    }
}

Re: About Question enthuware.ocpjp.ii.v11.2.3374 :

Posted: Thu Nov 07, 2019 7:01 am
by admin
Yes, it is correct. Default methods are indeed instance methods.
Section 9.4 of the Java 11 language specification clearly says on page 304:
A default method is an instance method declared in an interface with the default modifier.

Re: About Question enthuware.ocpjp.ii.v11.2.3374 :

Posted: Thu Nov 07, 2019 9:13 am
by Artuwok
Understand, thanks a lot.