Advertisements
Advertisements
प्रश्न
Find the output of the following code and write the type of inheritance:
class person(object):
def __init__(self,name,age):
self.name=name
self.age=age
def display1(self):
print "Name :",self.name
print "Age :",self.age
class student(object):
def __init__(self,rollno,marks):
self.rollno=rollno
self.marks=marks
def display(self):
print " Roll No:",self.rollno
print " Marks :",self.marks
class Gstudent(person,student):
def __init__(self,name,age,rollno,marks,stream):
super(Gstudent,self).__init__(self,stream)
person.__init__(self,name,age)
student.__init__(self,rollno,marks)
self.stream=stream
def display2(self):
self.display1() s
elf.display()
print " stream:",self.stream
p=Gstudent('Mona',20,12,99,'computer')
p.display2()लघु उत्तर
Advertisements
उत्तर
The given program contains typographical errors: self.display1() s and elf.display() must be corrected. Also, the erroneous super() call must be removed because both parent constructors are called explicitly.
Output after correction
Name : Mona
Age : 20
Roll No: 12
Marks : 99
stream: computer
Type of inheritance: Multiple inheritance (Gstudent inherits person and student).
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
