Unit 3 Cycle 2 Day 22: Error: Incorrect Override Signature

Unit 3 Advanced (Cycle 2) Day 22 of 28 Advanced

Error: Incorrect Override Signature

Section 3.13 — Overriding Methods

Key Concept

An incorrect override signature creates an overload instead of replacing the superclass method. Common mistakes include: different parameter types (int vs double), different number of parameters, different return type (which may or may not compile depending on the types), or a typo in the method name. When the original method is called polymorphically, the superclass version executes because the subclass version has a different signature. The AP exam creates questions where the intended override fails silently.

Consider the following classes.

public class Animal { public boolean equals(Object obj) { Animal a = (Animal) obj; return true; // simplified } } public class Dog extends Animal { public boolean equals(Dog other) { return true; // simplified } }

Does Dog's equals method override Animal's equals method?

Answer: (B) No, it overloads instead of overriding.

Animal's equals takes Object. Dog's equals takes Dog. Different parameter types = overloading, not overriding. To override, Dog's equals must also take Object.

Why Not the Others?

(A) The parameter types differ (Object vs Dog), so it is not an override.

(C) Overloading is valid and compiles fine.

(D) Override vs overload is determined at compile time, not runtime.

Common Mistake

To override a method, the signature must match exactly (same name, same parameter types). Changing Object to Dog creates a new overloaded method instead of replacing the parent's.

AP Exam Tip

The equals() override must use Object as the parameter type. Using the specific class type is the most common equals() mistake.

Review this topic: Section 3.13 — Overriding Methods • Unit 3 Study Guide

More Practice

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.