About Question enthuware.ocpjp.v8.2.1481 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
javalass
Posts: 54
Joined: Thu Mar 03, 2016 1:26 pm
Contact:

About Question enthuware.ocpjp.v8.2.1481 :

Post by javalass »

You cannot override a static method with a non-static method and vice-versa.
This is not quite true when it comes to interfaces (which is the case here). Static methods in interfaces are never inherited, so declaring a non-static method with the same signature as a static method from a superinterface is possible. This, for example, is fine:

Code: Select all

interface Readable {
    static String getAction() {
        return "read";
    }
}

interface ReadableInEnglish extends Readable {
    default String getAction() {
        return "read in English";
    }
}
and so is this:

Code: Select all

interface Readable {
    static String getAction() {
        return "read";
    }
}

interface ReadableInEnglish extends Readable {
    String getAction();    
}
but NOT these, since default methods ARE inherited:

Code: Select all

interface Readable {
    default String getAction() {
        return "read";
    }
}

interface ReadableInEnglish extends Readable {
    static String getAction() { //won't compile, can't override default method with static method
        return "read in English";
    }
}

Code: Select all

interface Readable {
    String getAction();
}

interface ReadableInEnglish extends Readable {
    static String getAction() { //won't compile, can't override abstract method with static method
        return "read in English";
    }
}
The answer to the question is correct though, this is just a note about the explanation provided.

admin
Site Admin
Posts: 10402
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1481 :

Post by admin »

You are right. Fixed.
thank you for your feedback!
Paul.

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests