Home » Python programs

Example of multiple inheritance in Python

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

Multiple inheritance

When we have one child class and more than one parent classes then it is called multiple inheritance i.e. when a child class inherits from more than one parent class.

In this program, we have two parent classes Personel and Educational and one child class named Student and implementing multiple inheritance.

Python code to demonstrate example of multiple inheritance

# Python code to demonstrate example of 
# multiple inheritance 

class Personel:
    def __init__(self):
    def setPersonel(self):
        self.__id=int(input("Enter Id: "))
        self.__name = input("Enter Name: ")
        self.__gender = input("Enter Gender: ")
    def showPersonel(self):
        print("Id: ",self.__id)
        print("Name: ",self.__name)
        print("Gender: ",self.__gender)

class Educational:
    def __init__(self):
    def setEducational(self):
        self.__stream=input("Enter Stream: ")
        self.__year = input("Enter Year: ")
    def showEducational(self):
        print("Stream: ",self.__stream)
        print("Year: ",self.__year)

class Student(Personel,Educational):
    def __init__(self):
        self.__address = ""
        self.__contact = ""
    def setStudent(self):
        self.__address = input("Enter Address: ")
        self.__contact = input("Enter Contact: ")

    def showStudent(self):
        print("Address: ",self.__address)
        print("Contact: ",self.__contact)

def main():
if __name__=="__main__":main()


Enter Id: 101
Enter Name: Prem Sharma  
Enter Gender: Male   
Enter Address: Nehru Place, New Delhi
Enter Contact: 0123456789
Enter Stream: Computer Science   
Enter Year: 2010 
Id:  101 
Name:  Prem Sharma   
Gender:  Male
Address: Nehru Place, New Delhi 
Contact: 0123456789 
Stream:  Computer Science
Year:  2010

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

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.