The Role of ‘super’ and ‘extends‘ in Object-Oriented Programming
Table of Contents
By Amelia Hernandez | NEW YORK – 2025/06/22 05:27:47
The terms ‘super’ and ‘extends’ play crucial roles in object-oriented programming (OOP), particularly in languages like Java and Python. While they serve different purposes, both are basic to inheritance, a core concept in OOP that allows new classes (subclasses) to inherit properties and behaviors from existing classes (superclasses or parent classes).
‘super’ Explained
The keyword ‘super’ is primarily used to access members (methods and attributes) of a parent class from within a subclass. It allows you to call a method defined in the superclass, even if the subclass has overridden that method. This is particularly useful when you want to extend the functionality of the parent class method rather than completely replacing it.
“super() lets you avoid referring to the base class explicitly, which can be nice.”
In Python, super() is often used in the __init__() method of a subclass to ensure that the superclass’s initialization logic is executed [3]. This is especially important in multiple inheritance scenarios, were the order of initialization matters. Using super() avoids explicitly naming the parent class, making the code more maintainable and less prone to errors [3].
‘extends’ Explained
The keyword ‘extends’ (used in Java) is used to declare that a class inherits from another class. It establishes an “is-a” relationship between the subclass and the superclass. Such as, if you have a class Animal and a class Dog, you can use extends to make Dog a subclass of Animal. This means that Dog inherits all the non-private members of Animal and can also add its own specific members.
In the context of Java Generics, extends is also used to specify upper bounds for type parameters. For example, List<? extends Number> means that the list can hold objects of type Number or any of its subclasses (e.g., Integer, Double) [1].
