INHERITANCE IN Presented by:
[Link] Jenifer
PYTHON 23PCA519
WHAT IS INHERITANCE?
Inheritance is defined as the mechanism of inheriting the properties
of the base class to the child class.
Syntax for defining a inheritance :
class BaseClass:
Body of base class
class DerivedClass(BaseClass):
Body of derived class
Derived class inherits features from the base class, adding
new features to it. This results into re-usability of code
Single Inheritance:
Single inheritance enables a derived class to
inherit properties from a single parent class,
thus enabling code reusability and the
addition of new features to existing code.
Multiple Inheritance:
When a class can be derived from more than
one base class this type of inheritance is
called multiple inheritances. In multiple
inheritances, all the features of the base
classes are inherited into the derived class.
Multilevel Inheritance :
In multilevel inheritance, features of the base
class and the derived class are further
inherited into the new derived class. This is
similar to a relationship representing a child
and a grandfather.
Hierarchical Inheritance:
Hierarchical Inheritance is the exact opposite
of multiple Inheritance. It means that there
are numerous derived child classes from a
single-parent [Link] more than one
derived class is created from a single base,
this type of inheritance is called hierarchical
inheritance.
Hybrid Inheritance:
Inheritance consisting of multiple types of
inheritance is called hybrid inheritance.
ADVANTAGES OF PYTHON
INHERITANCE
Modular Codebase: Increases modularity, i.e.,
breaking down the codebase into modules,
making it easier to understand. Here, each
class we define becomes a separate module
that can be inherited separately by one or
many classes.
Code Reusability: the child class copies all the
attributes and methods of the parent class
into its class and use. It saves time and
coding effort by not rewriting them, thus
following modularity paradigms.
DISADVANTAGES OF PYTHON
INHERITANCE
Decreases the Execution Speed: loading
multiple classes because they are
interdependent
Tightly Coupled Classes: Even though parent
classes can be executed independently, child
classes can only be conducted by defining
their parent classes.