Skip to main content
Module 3 · Lesson 1 of 27/22 in the course~14 min
Module lessons (1/2)

Inheritance with extends and super

Lesson preview5 hands-on exercises readyCourse Java · Module 3 — OOP Advanced

Extend existing classes, initialize inherited state with super(...), and protect with @Override.

What you'll learn in this lesson

  • Reuse state and behavior by defining a subclass via extends.
  • Correctly initialize inherited fields by invoking super(...) as the first child constructor statement.
  • Override methods safely using the @Override annotation and extend existing behaviors with super.method().

Overview

Inheritance allows a specialized class (subclass) to inherit fields and methods from a more general class (superclass) according to an "is-a" relationship (Dog is a Animal).

The subclass accesses the superclass's public and protected members, but NOT its private fields directly:

Sections covered in this lesson

  1. 11. Extending a Class with extends and protected
  2. 22. Constructor Chain: Rule of super(...)
  3. 33. Overwrite Safely with @Override and super.method()
  4. 44. Single and Class Inheritance final
  5. 5Try it yourself
Pro Lesson · Module 3 — OOP Advanced

Unlock "Inheritance with extends and super" and the full Course Java curriculum

Extend existing classes, initialize inherited state with `super(...)`, and protect with `@Override`.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Course Java plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.