Skip to content

The `super` Keyword

super (or super() in Java/Python) is used to access parent class members from within a child class. It allows:

  • Calling the parent constructor — initialize inherited state
  • Calling parent methods — extend, not replace, parent behavior

class Parent {
constructor(x) { this.x = x; }
method() { return "parent"; }
}
class Child extends Parent {
constructor(x, y) {
super(x); // Call parent constructor
this.y = y;
}
method() {
return super.method() + " + child"; // Call parent method
}
}
const child = new Child(10, 20);
console.log(child.method()); // "parent + child"

class Animal {
constructor(name) { this.name = name; }
speak() { return `${this.name} makes a sound`; }
}
class Dog extends Animal {
constructor(name, breed) {
super(name); // MUST call parent constructor before using `this`
this.breed = breed;
}
speak() {
// Call parent method and extend
return `${super.speak()} — but specifically barks!`;
}
}

RuleDescription
Must be firstsuper() must be called before accessing this
Only in derived classesCannot use super in non-inheriting classes
One level onlysuper accesses direct parent, not grandparent
ConstructorsParent constructor must be called explicitly in JS/Python/Java

Previous Topic: Types of Inheritance → Next Topic: Method Overriding →