Inheritance of Static Members
What You'll Learn
You'll learn that subclasses automatically inherit static methods and properties from their parent class, and can override them just like instance methods.
Static Members Flow Down the Class Hierarchy
When one class extends another, static members are inherited along with instance methods. This means child classes have access to all the parent's static methods and properties through their own class name.
Think of it like this: if a family business has a company logo (static property) and a corporate policy manual (static method), any subsidiary inherits those shared resources automatically. The subsidiary can use them as-is, or create their own versions.
How It Works
Static members are inherited through the class hierarchy, just like instance methods are inherited through the prototype chain:
class Animal {
static kingdom = 'Animalia';
static describe() {
return `All animals belong to kingdom ${this.kingdom}`;
}
}
class Dog extends Animal {
// Dog inherits static kingdom and describe()
}
console.log(Dog.kingdom); // "Animalia"
console.log(Dog.describe()); // "All animals belong to kingdom Animalia"
Overriding Static Members
Child classes can override static members, providing their own implementation:
class Cat extends Animal {
static kingdom = 'Felidae'; // Override property
static describe() { // Override method
return `Cats are special: ${this.kingdom}`;
}
}
console.log(Cat.kingdom); // "Felidae"
console.log(Cat.describe()); // "Cats are special: Felidae"
console.log(Animal.kingdom); // "Animalia" (parent unchanged)
The parent class remains unchanged—only the child's version is affected.
Key Takeaway: Subclasses inherit all static methods and properties from their parent class and can override them to provide specialized behavior, just like with instance methods.