Which class that implements the interface AA and returns the amount of the return value of a() of two given classes is declared correctly:

interface AA {
    int a();
}

class A implements AA {
    public int a() {
        return 1;
    }
}

class B implements AA {
    public int a() {
        return 1;
    }
}
Explanation
Class implementing an interface cannot narrow access modifier, so method a() has to be public.
Number of parameters cannot change with overriding, a(A a, B b) is a different method. But method a() has to be implemented for correct interface implementation.
Method a() is not static and you need an instance of an object to call it, so A.a() will not compile.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes