Computer Science A · Unit 9: Inheritance · 16 min read · Updated 2026-05-13
Inheritance — AP Computer Science A — AP Computer Science A
AP Computer Science A · Unit 9: Inheritance · 16 min read
1. Introduction to Inheritance, Superclasses, and Subclasses★★☆☆☆⏱ 3 min
Inheritance is a core object-oriented programming (OOP) mechanism that lets you create new classes from existing classes, reusing shared code, extending functionality, and modeling hierarchical real-world relationships. It eliminates redundant code by centralizing shared attributes and methods in a single parent class, rather than rewriting the same logic across multiple related classes. Per the AP CS A CED, inheritance makes up 10-15% of your total AP CS A exam score, tested on both multiple-choice and free-response questions.
2. `extends` and `super` Keyword Usage★★☆☆☆⏱ 4 min
To declare that a class inherits from another class, you use the `extends` keyword in Java. The `super` keyword has two critical use cases for subclasses: calling a superclass constructor, and accessing an overridden superclass method.
**Call superclass constructor**: `super()` must be the first line of a subclass constructor. If you do not explicitly write a `super()` call, Java automatically inserts a no-argument `super()` call. If your superclass does not have a no-argument constructor, you *must* explicitly call a parameterized `super()` to avoid a compile error.
**Call an overridden superclass method**: Use `super.methodName()` to access the superclass version of a method that you have overridden in the subclass.
3. Method Overriding and `@Override` Annotation★★★☆☆⏱ 3 min
Method overriding occurs when a subclass provides a specific implementation of a method that is already defined in its superclass. For a valid override, the method signature (name, parameter count, parameter types) must be exactly identical to the superclass method, the return type must be compatible, and the access modifier cannot be more restrictive than the superclass method.
4. Polymorphism and the IS-A Relationship★★★★☆⏱ 3 min
Inheritance creates an **IS-A relationship**: every subclass instance is a type of its superclass. For example, a `Dog` IS-A `Pet`, but a `Pet` is not necessarily a `Dog`.
Polymorphism (meaning "many forms") leverages this relationship: a superclass reference variable can refer to an object of any subclass type. At runtime, the JVM calls the method version matching the actual object type, not the reference type: this is runtime polymorphism, the primary form tested on AP CS A.
5. Introduction to Abstract Classes★★★★☆⏱ 3 min
Common Pitfalls
Why: Students forget Java only inserts an implicit no-argument `super()` call, which will fail if no such constructor exists
Why: Students do not remember the method signature must be exactly identical for an override
Why: Students assume all inherited members are directly accessible
Why: Students confuse reference type (which determines allowed methods) with actual object type (which determines method implementation)
Why: Students confuse abstract blueprint classes with concrete instantiable classes