J.II · Java 25 practice question
Class A declares a private instance method mA, and subclass C in the same package declares an instance method mC with the exact same signature. Does mC override mA?
Check answer and explanation
Correct answer: No, because an overridden method in A must be public, protected, or have package access in the same package.
Explanation
The method mC does not override mA because overriding requires mA to be public, protected, or declared with package access in the same package as C. A private method is never overridden.
Common trap
Being in the same package enables overriding package-access methods, not private methods. Not inheriting mA and having a subsignature are necessary conditions, but the accessibility requirement on mA must also be satisfied.
Source: JLS SE 25 §8.4.8.1. Overriding (by Instance Methods)
Checked against the cited text on 2026-11-25.