ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Python program to illustrate Single Inheritance (2)

Here, we will see a Python program to see how single inheritance works?
Submitted by Shivang Yadav, on February 19, 2021

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.

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

Python class & object programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.