Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

The Super Function

Sumit Rawal answered on May 17, 2023 Popularity 8/10 Helpfulness 5/10

Contents


More Related Answers

  • python super
  • superscript python
  • how to use the super
  • python super
  • super in javascirpt
  • javascript super
  • superset meaning in math
  • what is super keyword
  • what is super class in python
  • what is a super class
  • super() in python
  • JavaScript super() keyword
  • Super in javascript
  • What would be the behavior if this() and super() used in a method?
  • Usage of "super" keyword
  • super in programming
  • super keyword in javascript
  • how to use super in python
  • python call super constructor
  • super method with class in javascript
  • Show the difference between this() and super() with help of a code
  • how to use the super
  • how to use the super
  • Is it possible to use this() and super() both in same constructor?
  • super keyword in javascript
  • the super() function in Python

  • The Super Function

    1

    What is the super() function?

    The use of super() comes into play when we implement inheritance. It is used in a child class to refer to the parent class without explicitly naming it. It makes the code more manageable, and there is no need to know the name of the parent class to access its attributes.

    Note: Make sure to add parenthesis at the end to avoid a compilation error.

    Use cases of the super() function

    The super function is used in three relevant contexts:

    Accessing parent class properties

    Consider the fields named fuelCap defined inside a Vehicle class to keep track of the fuel capacity of a vehicle. Another class named Car extends from this Vehicle class. We declare a class property inside the Car class with the same name, i.e., fuelCap, but with a different value. Now, if we want to refer to the fuelCap field of the parent class inside the child class, we will have to use the super() function.

    Let’s understand this using the code below: 

    Popularity 8/10 Helpfulness 5/10 Language python
    Source: Grepper
    Link to this answer
    Share Copy Link
    Contributed on May 17 2023
    Sumit Rawal
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.