Overriding a method

Overriding a method means a subclass provides its own implementation of a method it inherited from its superclass, keeping the exact same method signature (name and parameter list) so the new version runs instead of the parent's version.

Verified for the 2027 AP Computer Science A examLast updated June 2026

What is Overriding a method?

Overriding is how a subclass says "I inherit this method, but I want it to do something different." The subclass writes a method with the same name, same parameter list, and a compatible return type as a method in its superclass. When that method is called on a subclass object, Java runs the subclass version, not the parent's.

The signature match is non-negotiable. If you change the parameter list, you haven't overridden anything. You've created a brand-new overloaded method, and the parent's version still lurks underneath. Java also lets you tag an overriding method with the @Override annotation, which tells the compiler to check your signature for you. The classic example is overriding toString() from the Object class so your objects print something useful instead of a memory-address-looking string.

Why Overriding a method matters in AP Computer Science A

Overriding lives at the heart of the inheritance unit in AP CSA (Unit 9), where you build subclass relationships with extends and customize inherited behavior. It's also the mechanism that makes polymorphism work. When you write Animal a = new Dog(); and call a.speak(), Java looks at the actual object type (Dog) at runtime and runs the overridden version. That runtime decision is what the exam means by polymorphic behavior, and without overriding, polymorphism would have nothing to choose between. Expect overriding to show up in multiple-choice trace questions and in the FRQ where you write or extend a class (often FRQ 2 or an inheritance-flavored prompt).

How Overriding a method connects across the course

Inheritance (Unit 9)

Overriding only exists because of inheritance. A subclass automatically gets its parent's methods through extends, and overriding is the tool for replacing the ones that don't fit. No inheritance relationship, no overriding.

Polymorphism (Unit 9)

Polymorphism is overriding in action. When a superclass reference points to a subclass object, Java picks the overridden method based on the object's actual type at runtime. Overriding writes the alternate behavior; polymorphism is the dispatch system that selects it.

Method Signature (Units 5 & 9)

The signature (method name plus parameter list) is the matching rule for overriding. Same signature in the subclass means override. Different parameter list means overload, which is a completely different mechanism and a favorite MCQ trap.

@Override (Unit 9)

The @Override annotation is your safety net. It makes the compiler verify that you actually matched a superclass method's signature. If you typo the name or parameters, you get a compile error instead of a silent bug.

Is Overriding a method on the AP Computer Science A exam?

Multiple-choice questions test two things. First, recognition, like "which method signature correctly overrides this superclass method?" where wrong answers sneak in a changed parameter list or return type. Second, code tracing, where a superclass reference calls an overridden method and you have to know the subclass version runs. The free-response section tests it actively. When an FRQ asks you to write a subclass, you often need to override an inherited method (like toString() or an abstract-feeling behavior method) with the exact signature from the parent. Copying the parent's method header precisely, then writing new body code, is the move. No released FRQ requires the word "override" itself, but inheritance FRQs regularly require you to do it.

Overriding a method vs Overloading a method

Overriding happens between a superclass and subclass with the SAME signature (same name, same parameters), replacing inherited behavior. Overloading happens within one class (or via inheritance) with the same name but DIFFERENT parameter lists, creating multiple versions that coexist. Quick check: same signature in a subclass means override; different parameter list means overload.

Key things to remember about Overriding a method

  • Overriding means a subclass provides a new implementation for a method it inherited, using the exact same method signature as the superclass version.

  • If the parameter list is different from the parent's method, it is overloading, not overriding, and the parent's method is still inherited unchanged.

  • When a superclass reference points to a subclass object, calling an overridden method runs the subclass version, which is how polymorphism works in Java.

  • The @Override annotation is optional but smart because the compiler will catch signature mismatches that would otherwise silently create a new method.

  • Overriding toString() from the Object class is the most common example on the AP exam, letting your objects produce readable String output.

  • An overriding method cannot have a more restrictive access modifier than the method it overrides, so a public method must stay public in the subclass.

Frequently asked questions about Overriding a method

What is overriding a method in AP Comp Sci A?

Overriding is when a subclass redefines a method it inherited from its superclass, keeping the same name and parameter list so its version replaces the parent's behavior. It's central to the inheritance unit and to how polymorphism works on the exam.

What's the difference between overriding and overloading a method?

Overriding uses the same signature across a superclass-subclass pair to replace behavior. Overloading uses the same method name with different parameter lists so multiple versions coexist. MCQs love testing this by changing one parameter type in an answer choice.

Do I have to use @Override when overriding a method?

No, Java doesn't require it, and the override works without it. But you should use it anyway because the compiler will flag your code if the signature doesn't actually match a superclass method, catching typos before they become bugs.

Can an overriding method have a different return type?

Mostly no. The return type must be the same (or a subclass of the original return type, called a covariant return). For AP CSA purposes, keep the return type identical to the superclass method's return type and you'll be safe.

Which version of a method runs when I use a superclass reference?

The subclass version. If you write Animal a = new Dog(); and Dog overrides speak(), then a.speak() runs Dog's version because Java decides at runtime based on the actual object type, not the reference type. This is the classic polymorphism trace question.