J.II · Java 25 practice question
For an instance method mC declared in or inherited by class C to override an instance method mA declared in class A, which structural condition must hold?
Check answer and explanation
Correct answer: C must be a subclass of A, C must not inherit mA, and mC's signature must be a subsignature of mA's signature.
Explanation
Overriding requires that C is a subclass of A, C does not inherit mA, and the signature of mC is a subsignature of the signature of mA as a member of the supertype of C that names A.
Common trap
C does not have to be a direct subclass of A, and C specifically must not inherit mA for mC to override it. mC can be inherited by C rather than declared directly, and mA does not need to be abstract.
Source: JLS SE 25 §8.4.8.1. Overriding (by Instance Methods)
Checked against the cited text on 2026-11-25.