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 "Name :",self.name

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(person):
def __init__(self,name,age,rollno,marks): 
     super(student,self).__init__(name,age)
     self.rollno=rollno
     self.marks=marks
     def display(self):
     self.display1()
     print " Roll No:",self.rollno
     print " Marks :",self.marks
     p=student('Mona',20,12,99)
p.display()
Very Short Answer
Advertisements

Solution

After correcting indentation, the code creates an object of student.

Output

Name : Mona
Age : 20
Roll No: 12
Marks : 99

Type of inheritance: Single inheritance (student inherits person).

shaalaa.com
  Is there an error in this question or solution?
Chapter 4: Inheritance - EXERCISE [Page 78]

APPEARS IN

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

Englishहिंदीमराठी


      Forgot password?
Use app×