Course contentsShow
← Java
Lesson 404 of 2,87010. Inheritance FundamentalsFree lesson

Using super to Call Overridden Methods

Understand how subclasses use super.methodName() to invoke the superclass version of an overridden method.

Using super to Call Overridden Methods

What you'll learn: How to use super.methodName() to explicitly call the superclass version of a method you've overridden in your subclass.

The Core Idea

When a subclass overrides a method from its superclass, the subclass version completely replaces the superclass version for that subclass's objects. But sometimes you don't want to throw away the superclass logic entirely—you want to extend it or supplement it.

The super keyword lets you reach "up" the inheritance hierarchy and invoke the superclass's version of a method, even after you've overridden it. Think of it like saying, "Do what my parent class would do, then I'll add my own behavior."

How It Works

The syntax is straightforward:

super.methodName();

This calls the superclass's implementation of methodName(), not your subclass's overridden version.

Practical Example

class Animal {
    public void makeSound() {
        System.out.println("Some generic animal sound");
    }
}

class Dog extends Animal {
    @Override
    public void makeSound() {
        super.makeSound();  // Call Animal's version first
        System.out.println("Woof!");
    }
}

When you call makeSound() on a Dog object, it prints:

Some generic animal sound
Woof!

The super.makeSound() call executes the Animal class's logic, then the Dog class adds its own behavior.

Why This Matters

This pattern is extremely common when you want to extend functionality rather than completely replace it. You preserve the superclass's work while layering on subclass-specific details.

Key Takeaway: Use super.methodName() to invoke the superclass version of an overridden method, allowing you to build upon inherited behavior rather than discarding it.