OCJP

Multiple Inheritance in Python

Python supports Multiple Inheritance. We can place multiple Parent class in Child class. Following example shows how it works:

class Sports:
    def Play(self):
        print("Play Games")

    def showResult(self):
        print("Result of Sports")

class Study:
    def Exam(self):
        print("Appear to Exam")

    def showResult(self):
        print("Result of Exam")
        

class Student(Sports,Study):
    def show(self):
        super().Play()
        super().Exam()
        super().showResult()  #Left to Right Search in Parent Classes
        Study().showResult() #can call like this
    
S=Student()
S.show()

Here super().showresult() will called for Sports as Sports is Left in Inheritance.

Leave a Reply

Your email address will not be published. Required fields are marked *


× How can I help you?