Skip to content
Adaptive

Learn Java Inheritance and Recursion

Read the notes, then try the practice. It adapts as you go.When you're ready.

Session Length

~15 min

Adaptive Checks

14 questions

Transfer Probes

8

Lesson Notes

Inheritance is a fundamental object-oriented programming mechanism in Java that allows a subclass to inherit fields and methods from a superclass, promoting code reuse and establishing an is-a relationship. Subclasses extend superclasses using the extends keyword and can override inherited methods to provide specialized behavior. The super keyword accesses parent constructors and methods, and all classes ultimately inherit from java.lang.Object.

Polymorphism enables a superclass reference to hold a subclass object, with method calls resolved at runtime based on the actual object type (dynamic dispatch). Abstract classes define method signatures that subclasses must implement, while interfaces specify contracts that classes can implement across inheritance hierarchies. Understanding upcasting, downcasting, and the instanceof operator is essential for working with polymorphic code.

Recursion is a technique where a method calls itself to solve problems by breaking them into smaller subproblems. Every recursive method requires a base case (stopping condition) and a recursive case that moves toward the base case. Classic recursive algorithms include factorial, Fibonacci, binary search, and merge sort. This topic covers AP Computer Science A Units 9 and 10, comprising approximately 10-15% of the AP exam.

You'll be able to:

  • Create subclass-superclass hierarchies using extends and call parent constructors with super()
  • Override inherited methods and explain how dynamic dispatch determines which method executes at runtime
  • Distinguish between abstract classes and interfaces and explain when to use each
  • Write recursive methods with correct base cases and recursive cases to solve problems
  • Trace recursive calls to predict output and identify common recursion errors like missing base cases

One step at a time.

Interactive Exploration

Adjust the controls and watch the concepts respond in real time.

Key Concepts

Inheritance (extends)

A mechanism where a subclass inherits fields and methods from a superclass using the extends keyword, establishing an is-a relationship and promoting code reuse.

Example: class Dog extends Animal { } // Dog IS-A Animal and inherits all Animal fields and methods.

Method Overriding

A subclass provides its own implementation of a method inherited from the superclass. The overriding method must have the same signature (name, parameters, return type).

Example: class Dog extends Animal { @Override public String speak() { return "Woof"; } } // Overrides Animal's speak() method.

super Keyword

A reference to the superclass used to call the parent constructor (super()), access overridden methods (super.method()), or reference parent fields.

Example: public Dog(String name) { super(name); } // calls Animal's constructor with name parameter.

Polymorphism

The ability of a superclass reference variable to hold a subclass object. Method calls are resolved at runtime based on the actual object type (dynamic dispatch).

Example: Animal a = new Dog(); a.speak(); // calls Dog's speak() method, not Animal's, due to dynamic dispatch.

Abstract Class

A class declared with the abstract keyword that cannot be instantiated. It may contain abstract methods (no body) that subclasses must implement.

Example: abstract class Shape { abstract double area(); // subclasses MUST implement this public void display() { System.out.println(area()); } // concrete method }

Interface

A reference type that defines a contract of method signatures that implementing classes must provide. A class can implement multiple interfaces.

Example: interface Drawable { void draw(); } class Circle implements Drawable { public void draw() { /* implementation */ } }

Recursion

A programming technique where a method calls itself to solve a problem by breaking it into smaller instances of the same problem.

Example: public int factorial(int n) { if (n <= 1) return 1; // base case return n * factorial(n - 1); // recursive case }

Base Case

The stopping condition in a recursive method that prevents infinite recursion. It returns a value directly without making another recursive call.

Example: if (n <= 1) return 1; // base case for factorial: when n is 0 or 1, return 1 without recursing.

More terms are available in the glossary.

Explore your way

Choose a different way to engage with this topic β€” no grading, just richer thinking.

Explore your way β€” choose one:

Explore with AI β†’

Concept Map

See how the key ideas connect. Nodes color in as you practice.

Worked Example

Walk through a solved problem step-by-step. Try predicting each step before revealing it.

Adaptive Practice

This is guided practice, not just a quiz. Hints and pacing adjust in real time.

Small steps add up.

What you get while practicing:

  • Math Lens cues for what to look for and what to ignore.
  • Progressive hints (direction, rule, then apply).
  • Targeted feedback when a common misconception appears.

Teach It Back

The best way to know if you understand something: explain it in your own words.

Keep Practicing

More ways to strengthen what you just learned.

Java Inheritance and Recursion Adaptive Course - Learn with AI Support | PiqCue