Lecture 8 - Inheritance in Python
Lecture 8 - Inheritance in Python
Inheritance in Python
Content
sazzad@diucse
What is Inheritance?
Inheritance allows us to define a class that inherits all the methods
and properties from another class.
• Parent class: is the class being inherited from, also called base
class.
• Child class is the class that inherits from another class, also called
derived class.
sazzad@diucse
Inheritance Example
Child Class
sazzad@diucse
Create Base Class
sazzad@diucse
Create Child Class
sazzad@diucse
Create Object & Call Base Class Method
sazzad@diucse
Benefits of Inheritance
sazzad@diucse
Use the Super() Function
• Python has a super() function that will make the child class inherit
all the methods and properties from its parent
• By using the super() function, you do not have to use the name of
the parent element, it will automatically inherit the methods and
properties from its parent.
sazzad@diucse
Use the Super() Function
sazzad@diucse
Overriding
sazzad@diucse
Overriding Example
sazzad@diucse
Overriding Example
sazzad@diucse
Thank You
sazzad@diucse