How to Do Hybrid Inheritance in Python
Posted on: February 28, 2021 by Ariessa Norramli
In this article, you will learn how to do hybrid inheritance in Python.
Hybrid inheritance is a combination of multilevel inheritance and multiple inheritance.
# This class is the base class
class Father:
def func1(self):
print("This function is in Father")
# This class inherits from Father
class FirstChild(Father):
def func2(self):
print("This function is in FirstChild")
# This class inherits from Father
class SecondChild(Father):
def func3(self):
print("This function is in SecondChild")
# This class inherits from both FirstChild and Father
class GrandChild(FirstChild, Father):
def func4(self):
print("This function is in GrandChild")
object = GrandChild()
object.func1()
# This function is in Father
object.func2()
# This function is in FirstChild
Note: The class GrandChild
is an example of hybrid inheritance.
Share on social media
//