English

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

Advertisements
Advertisements

Question

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()
Short Answer
Advertisements

Solution

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
  Is there an error in this question or solution?
Chapter 4: Inheritance - EXERCISE [Page 80]

APPEARS IN

CBSE Computer Science with Python [English] Class 12
Chapter 4 Inheritance
EXERCISE | Q 14. c. | Page 80
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×