हिंदी

Explain the significance of super() function.

Advertisements
Advertisements

प्रश्न

Explain the significance of super() function.

कोड लेखन
स्पष्ट कीजिए
Advertisements

उत्तर

super() is used in a derived class to access methods of its parent class, especially the parent constructor.

class Student(Person):
    def __init__(self, name, roll_no):
        super().__init__(name)
        self.roll_no = roll_no

It avoids repeating parent-class code and is especially useful in multilevel inheritance.

shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 4: Inheritance - EXERCISE [पृष्ठ ७८]

APPEARS IN

सीबीएसई Computer Science with Python [English] Class 12
अध्याय 4 Inheritance
EXERCISE | Q 9. | पृष्ठ ७८
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×