Python Forum

Full Version: How inheritance works in Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am beginner to OOPS concepts. I have written small code to understand inheritance concept. But i had a query while writing code. As per Inheritance concept, the derived class inherits properties of base class. In below example I have created two classes with different name but same methods/functions and passed to these classes to derived class. Now here query is how call the myClass1 method in derived class. because it is same method

Can someone help us to understand the concept quickly.

class myClass():
    def method1(self):
        print("Guru99")

class myClass1():
    def method1(self):
        print("Guru991")


class childClass(myClass, myClass1):
    def method2(self):
        print("ChildClass Method1")


def main():
    c2 = childClass()
    c2.method1() # myClass.method1()
    c2.method2()
    # c2.method1() # myClass1.method1()