English

Complete the following code: class employee(object): def __init__(self,no,name,age): self.no=no self.name=_____ #complete the statement self.age=______ #complete the statement def printval(self):

Advertisements
Advertisements

Question

Complete the following code:

class employee(object):
def __init__(self,no,name,age):
     self.no=no
     self.name=_____        #complete the statement
     self.age=______       #complete the statement
def printval(self):
     print "Number:",self.no
     print "Name :",self.name
     print "Age :",self.age
class pay(object):
     def __init__(self,dept,salary): #complete the definition
     __________
     __________
     def display(self):                  #complete the definition
     ____________________           # call printval()
     __________________         # print dept
     ___________________  # print salary
Code Writing
Advertisements

Solution

class employee(object):
    def __init__(self, no, name, age):
        self.no = no
        self.name = name
        self.age = age

    def printval(self):
        print("Number:", self.no)
        print("Name :", self.name)
        print("Age :", self.age)

class pay(employee):
    def __init__(self, no, name, age, dept, salary):
        employee.__init__(self, no, name, age)
        self.dept = dept
        self.salary = salary

    def display(self):
        self.printval()
        print("Department:", self.dept)
        print("Salary:", self.salary)
shaalaa.com
  Is there an error in this question or solution?
Chapter 4: Inheritance - EXERCISE [Page 81]

APPEARS IN

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

Englishहिंदीमराठी


      Forgot password?
Use app×