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
@Overrideannotation and extend existing behaviors withsuper.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
- 11. Extending a Class with
extendsandprotected - 22. Constructor Chain: Rule of
super(...) - 33. Overwrite Safely with
@Overrideandsuper.method() - 44. Single and Class Inheritance
final - 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.