Q:

Python program to illustrate Single Inheritance (2)

belongs to collection: Python class & object programs

0

Single Inheritance:

When a class inherits the properties of another class, it is known as single inheritance.

Python | Single Inheritance

The class that inherits the properties of another class is known as derived Class.

The class whose properties are inherited is known as base Class.

Classes used in the program:

  • Class : Employee
    • Method : getEmployeeInfo() : Gets input of the employee information from the user.
    • Method : printEmployeeInfo() : prints the information of the employee.
    • Method : getSalary() : return the salary of the employee.
  • Class Perks :
    • Method: getPerks() : calculates all perks of the employee.
    • Method : putPerks() : prints all perks and employee details of the employee.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program to illustrate single inheritance in Python

class Employee:
 def getEmployeeInfo(self):
   self.__id=input("Enter Employee Id:")
   self.__name=input("Enter Name:")
   self.__salary=int(input("Enter Employee Salary:"))

 def printEmployeeInfo(self):
   print("ID : ", self.__id," , name : ", self.__name, ", Basic Salary : ", self.__salary)

 def getSalary(self):
     return(self.__salary)

class Perks(Employee):
    def getPerks(self):
        self.getEmployeeInfo()
        sal=self.getSalary()
        self.__da=sal*35/100
        self.__hra = sal * 17 / 100
    
    def printPerks(self):
        self.printEmployeeInfo()
        print("Total Salary ", (self.getSalary() + self.__da + self.__hra ) )

S=Perks()
S.getPerks()

print("Employee information ")
S.printPerks()

Output:

Enter Employee Id:0012
Enter Name:shivang 
Enter Employee Salary:50000
Employee information 
ID :  0012  , name :  shivang  , Basic Salary :  50000
Total Salary  76000.0

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python class & object programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Example of inheritance with two child (derived) cl... >>
<< Example of single inheritance in Python...