मराठी

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):

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(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
class Gstudent(student):
def __init__(self,name,age,rollno,marks,stream):
     super(Gstudent,self).__init__(name,age,rollno,marks)
self.stream=stream
def display2(self):
     self.display()
     print " stream:",self.stream
p=Gstudent('Mona',20,12,99,'computer')
p.display2()
अति संक्षिप्त उत्तर
Advertisements

उत्तर

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

Output

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

Type of inheritance: Multilevel inheritance: person → student → Gstudent.

shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 4: Inheritance - EXERCISE [पृष्ठ ७९]

APPEARS IN

सीबीएसई Computer Science with Python [English] Class 12
पाठ 4 Inheritance
EXERCISE | Q 14. b. | पृष्ठ ७९
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×