Q&A CBSE12A-2018-B02A #6109
Question:
What is the advantage of super() function in inheritance? Illustrate the same with the help of an example in Python.
Answer:
In Python, super() function is used to call the methods of base class which have been extended in derived class.
class person(object):
def __init__(self,name,age):
self.name=name
self.age=age
def display(self):
print self,name, self.Age
class student(person):
def __init__(self,name,age,rollno,marks):
super(student,self)._init_(self, name, age)
self.rollno=rollno
self.marks=marks
def getRoll(self):
print self.rollno, self.marks
