Here, we will see a Python to illustrate the working of constructor call using super() to call inherited class.
- Constructor are the functions of a class that are invoked at the time of object creation.
- Inheritance is the property of object-oriented programming in which one class inherits the properties of another class.
- Inherited Class is the class whose properties are inherited by another class.
- super() method is used to call the member of the inherited class in the current class.
Program to illustrate the working of our solution
Output:
Explanation:
In the above code, we have a created 5 class that inherits in hybrid inheritance form depicted here,
There are two hybrid inheritances. Then we have created objects of class penguin and dog. Their constructors made calls to the constructors of their parent classes using super() method and printed the output.
need an explanation for this answer? contact us directly to get an explanation for this answer