Tutorial 3 : OOPs in Python — Inheritance
Missed previous tutorial — Click here
In this tutorial we will cover following topics :
Terminologies :
1) Inheritance
- one class inherits the attributes and methods of another class
2) Parent class
- the class whose properties and methods are inherited
3) Child/Derived class
- the class that inherits the properties from the parent class
- a child class can have its own properties and methods
Three purposes of Inheritance :
- overwriting the method of parent class in a derived class
- defining new method in a derived class
- calling the methods of parent class for a derived class object even if that method is not defined in a derived class
Example 1 :
Let’s first define a parent class and create it’s object :
Now let’s define a derived class and inherit the parent class methods in it and see if all the aforementioned purposes are really getting served :
So we can clearly see that all the purposes are served using inheritance.
Example 2 :
Let’s first define a parent class and create it’s object :
Now let’s define a derived class and inherit the parent class methods in it and see if all the aforementioned purposes are really getting served :
Example 3 :
Let’s first define a parent class and create it’s object :
Now let’s define a derived class and inherit the parent class methods in it and see if all the aforementioned purposes are really getting served :
Multiple inheritance :
Congratulations !!
You have completed third tutorial. We will learn Polymorphism in next tutorial.
Take a deep breathe and move to the next tutorial.