0% found this document useful (0 votes)
9 views30 pages

Lec-14 Inheritance

The document discusses the concept of inheritance in Object-Oriented Programming (OOP), detailing the roles of base and derived classes. It explains various types of inheritance, including single, multilevel, and multiple inheritance, as well as the concept of polymorphism and function overriding. Additionally, it highlights the importance of access specifiers like protected and the role of the scope resolution operator in function overriding.

Uploaded by

Shreya Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views30 pages

Lec-14 Inheritance

The document discusses the concept of inheritance in Object-Oriented Programming (OOP), detailing the roles of base and derived classes. It explains various types of inheritance, including single, multilevel, and multiple inheritance, as well as the concept of polymorphism and function overriding. Additionally, it highlights the importance of access specifiers like protected and the role of the scope resolution operator in function overriding.

Uploaded by

Shreya Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Object Oriented

Programming
Mohona Ghosh
Inheritance
• Inheritance is an important pillar of OOP
• It is the mechanism by which one class is allowed to inherit the
features of another class
• It allows us to create a new class (derived class) from an existing class
(base class).
Inheritance
Inheritance
Inheritance classes
• Base Class (or superclass): The class whose properties are inherited
by sub class is called Base Class or Super class.
• Derived Class (or subclass): The class that inherits properties from
another class is called Sub class or Derived Class.
Types of Inheritance
Defining
Derived
Classes
Defining Derived Classes

A derived class doesn’t


inherit access to private
data members.
Single inheritance
Single
inheritance
Protected mode

Like private members, protected members are inaccessible


outside of the class. However, they can be accessed by derived
classes and friend functions.

We need protected members if we want to hide the data of a


class, but still want that data to be inherited by its derived
classes.
Protected mode
Protected mode
Protected members
Protected mode
Multilevel Inheritance
Multilevel Inheritance
Multiple Inheritance
Multiple Inheritance
Polymorphism in inheritance
• Inheritance lets us inherit attributes and methods
from another class.
• Polymorphism can also be used in those methods to
perform different tasks. This allows us to perform a
single action in different ways.
Function Overriding
• Suppose, the same function is declared in both the derived class and
the base class.
• Now if we call this function using the object of the derived class,
which function will be called ??
• Function of base class or function of derived class ?
• The function of the derived class is executed.
• This is known as function overriding in C++.
• The function in derived class overrides the function in base class.
Polymorphism in inheritance

In this case, objects belonging to different classes are able to respond to


the same message, but in different forms
Function Overriding
Runtime Polymorphism
• When the relationship between the definition of different
functions and their function calls, is determined during the
compile-time, it is known as compile-time polymorphism. This
type of polymorphism is also known as static or early binding
polymorphism.
• Function Overloading and Operator overloading
• In runtime polymorphism, the compiler resolves the object at
run time and then it decides which function call should be
associated with that object. It is also known as dynamic or late
binding polymorphism.
• Function Overriding and Virtual Functions
Role of scope resolution (::) in Function Overriding
• To access the overridden function of the base
class, we use the scope resolution operator ::.
Role of scope resolution (::) in Function Overriding

You might also like