INHERITANCE
INHERITANCE
Inheritance is a fundamental concept in object-oriented programming (OOP) that
allows a class (called a child or derived class) to inherit attributes and methods
from another class (called a parent or base class). This promotes code reuse,
modularity, and a hierarchical class structure.
• Parent Class:
• This is the base class from which other classes inherit.
• It contains attributes and methods that the child class can reuse.
• Child Class:
• This is the derived class that inherits from the parent class.
• The syntax for inheritance is class ChildClass(ParentClass).
In object-oriented programming, a parent class (also known as a base
class) defines common attributes and methods that can be inherited by
other classes. These attributes and methods serve as the foundation for
the child classes. By using inheritance, child classes can access and
extend the functionality provided by the parent class.
1) Which is the simplest form of
INHERITANCE TYPES inheritance where a child class inherits
attributes and methods from only one
parent class.??
2) This type of inheritance contains
multiple derived classes that are
inherited from a single base class. This is
similar to the hierarchy within an
organization.
3) In multilevel inheritance, a class is
derived from another derived class. There
exists multiple layers of inheritance. We can
imagine it as a grandparent-parent-child
relationship.
4) Which allows you to construct a
class based on more than one parent
classes. The Child class thus inherits
the attributes and method from all
parents.
5) Combination of two or more types of
inheritance is called as Hybrid Inheritance.
SINGLE INHERITANCE
HIERARCHICAL INHERITANCE
MULTILEVEL INHERITANCE
MULTIPLE INHERITANCE
SUPER ()
SUPER() FUNCTION
super() function is used to call the parent class’s methods. In particular, it is commonly used in the child class’s
__init__() method to initialize inherited attributes. This way, the child class can leverage the functionality of the
parent class. super() gives you access to methods from the parent class.
•The super() function is used inside th
__init__() method of Employee to call
the constructor of Person and initialize
the inherited attributes (name and
idnumber).
•This ensures that the parent class
functionality is reused without needin
to rewrite the code in the child class.