Example of single inheritance in Python

Here, we are going to implement a python program to demonstrate an example of single inheritance.
Submitted by Pankaj Singh, on June 25, 2019

In this program, we have a parent class named Details and child class named Employee, we are inheriting the class Details on the class Employee. And, finally creating an object of Employee class and by calling the method setEmployee() – we are assigning the values to the class variables and printing the values using showEmployee() function.

Python code to demonstrate example of single inheritance

# Python code to demonstrate example of 
# single inheritance

class Details:
    def __init__(self):
        self.__id="<No Id>"
        self.__name="<No Name>"
        self.__gender="<No Gender>"
    def setData(self,id,name,gender):
    def showData(self):
        print("Name\t\t:", self.__name)
        print("Gender\t\t:", self.__gender)

class Employee(Details): #Inheritance
    def __init__(self):
        self.__company="<No Company>"
        self.__dept="<No Dept>"
    def setEmployee(self,id,name,gender,comp,dept):
    def showEmployee(self):
        print("Company\t\t:", self.__company)
        print("Department\t:", self.__dept)

def main():
    e.setEmployee(101,"Prem Sharma","Male","New Delhi",110065)

if __name__=="__main__":


Id              : 101
Name            : Prem Sharma
Gender          : Male
Company         : New Delhi
Department      : 110065

Python class & object programs »

Comments and Discussions

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.