This content originally appeared on CodeSource.io and was authored 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.
The post How to Do Hybrid Inheritance in Python appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Ariessa Norramli
Ariessa Norramli | Sciencx (2021-02-28T17:28:23+00:00) How to Do Hybrid Inheritance in Python. Retrieved from https://www.scien.cx/2021/02/28/how-to-do-hybrid-inheritance-in-python/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.