You are on page 1of 23

Introduction

TMSS Engineering College


Computer Science and Engineering
Object Oriented Programming With C++
Presentation Topic – “Inheritance”
Group Number – 02
Group Member ID Number
Sabiha Khanom 162002
Afrin Leena 162015
Nahid Hasan 162016
Mohaiminul Islam 162023
Tanvir Ahmed 162028
Inheritance in C++
Inheritance : The process of obtaining the data members and
methods from one class to another class is known as inheritance. It
is one of the fundamental features of object-oriented programming.

• The Mechanism of deriving a new class from an old one is


called inheritance.

• Inheritance is the capability of one class to inherit


properties from another class.

• The most important advantage of inheritance is code


reusability.
Real life example of Inheritance

The real life example of inheritance is child and parents, all


the properties of father are inherited into son.
Advantage of inheritance

• If we develop any application using this concept than that


application have following advantages,
• Application development time is less.
• Application take less memory.
• Application execution time is less.
• Application performance is enhance (improved).
• Redundancy (repetition) of the code is reduced or minimized
so that we get consistence results and less storage cost.
Base Class and Derived Class
• Base Class : In the inheritance the class which is give
data members and methods is known as base or super or
parent class.

• Derived Class : The class which is taking the data


members and methods is known as sub or derived or child
class.

A class can be derived from more than one classes, which


means it can inherit data and functions from multiple base
classes. The old class is referred to as the base class and
the new one is called the derived class.
Syntax Of Creating A Derive Class

To define a derived class, we use a class derivation list to specify


the base class. A class derivation list names one or more base
classes and has the form:
class Derive_class_name : Visibility_mode Base_class_name
{
// data members
// methods
};
Visibility Mode
It is the keyword that controls the visibility and availability of
inherited base class members in the derived class. It can be either
private or protected or public.

• Private Inheritance: It is the inheritance facilitated by private


visibility mode. In private inheritance, the protected and public
members of base class become private members of the derived class.
• Public Inheritance: It is the inheritance facilitated by public
visibility mode. In public inheritance, the protected members of
base class become protected members of the derived class and
public members of the base class become public members of derived
class.
• Protected Inheritance: It is the inheritance facilitated by protected
visibility mode. In protected inheritance , the protected and public
members of base class become protected members of the derived
class.
Visibility Mode
Visibility mode at a glance :
Derived class visibility
Base Class
Visibility Public Private Protected
derivation derivation derivation
Private Not inherited Not inherited Not inherited
Protected Protected Private Protected
Public Public Private Protected
Types of Inheritance
Based on number of ways inheriting the feature
of base class into derived class it have five
types they are:

• Single inheritance
• Multilevel inheritance
• Multiple inheritance
• Hierarchical inheritance
• Hybrid inheritance
Single Inheritance
• In single inheritance there exists single base class and single
derived class. Single inheritance enables a derived class to
inherit properties and behavior from a single parent class.

• It allows a derived class to inherit the properties and behavior


of a base class, thus enabling code reusability

A B
Base Class Derived Class

Fig : Single Inheritance


Single Inheritance : Example

Output :
Multilevel Inheritance

A In C++ programming, the multilevel


Base Class inheritance is a technique or process in
which a child class is inherited from
B another derived class.
Intermediate
Base-Class

C
Derived Class

Fig : Multilevel Inheritance


Multilevel Inheritance : Example

Output :
Multiple Inheritance
Multiple inheritance is a feature of some object-
oriented computer programming languages in which
a derived class can inherit characteristics and
features from more than one base class.

A B C
Base Class Base Class Base Class

D
Derived Class

Fig : Multiple Inheritance


Multiple Inheritance : Example

Output :
Hierarchical Inheritance

When more than one classes are derived from a


single base class, such inheritance is known as
Hierarchical Inheritance, where features that are
common in lower level are included in parent class.

A
Base Class

B C
Derived Class Derived Class

Fig : Hierarchical Inheritance


Hierarchical Inheritance : Example

Output :
Hybrid Inheritance

Multilevel Inheritance Hybrid Inheritance is a method where


one or more types of inheritance are
A combined together and used.
Base Class

B
Intermediate C
Base-Class Base Class

D
Derived Class
Multilple Inheritance

Fig : Hybrid Inheritance


Hybrid Inheritance : Example

Output :
Reference:
1. Jafrin Madam’s class note.
2. http://www.tutorialspoint.com/
3. http://www.cplusplus.com/
Thanks
Everyone
Any Questions

You might also like