Python Programming - Inheritance - Discussion

Discussion Forum : Inheritance - General Questions (Q.No. 77)
77.
Consider the following code:
class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

class Employee(Person):
    def __init__(self, name, age, employee_id):
        super().__init__(name, age)
        self.employee_id = employee_id
What is the primary advantage of using super().__init__(name, age) in the Employee class constructor?
To call the constructor of the Employee class
To create a new instance of the Person class
To initialize attributes of the Person class in the Employee class
To access superclass attributes directly
Answer: Option
Explanation:
super().__init__(name, age) is used to call the constructor of the superclass Person and initialize the name and age attributes.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.