Practice mode Java

A superclass declares public void f(). Which access level may a subclass use when overriding f()?

Correct answer A. public only

Explanation

An overriding method must offer at least the access of the method it overrides, because a subclass object must be usable wherever the superclass is expected. Since public is the widest level, only public is allowed here. Attempting protected or weaker access is a compile-time error. A protected method, by contrast, may be widened to public.

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.