Inheritance Single and Multilevel inheritance.pptx

rupanaveen24 8 views 17 slides Aug 30, 2025
Slide 1
Slide 1 of 17
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17

About This Presentation

C++


Slide Content

Types of Inheritance Core pillars of Object-oriented programming

What is Inheritance?

Inheritance: The capability of a class to derive properties and characteristics from another class is calledĀ  Inheritance . That is, the derived class (child class) can use the member functions of the base class(parent class) also. Syntax looks like,

Types of inheritance: Single inheritance: Multilevel inheritance: Multiple inheritance Hybrid inheritance Hierarchical inheritance.

1. Single Inheritance In single inheritance, a class is allowed to inherit from only one class. i.e., one base class is inherited by one derived class only. It allows the derived class to use the member functions and data members of the base class.

Example:

Example:

Printing details of a person using inheritance:

Printing details of a person using inheritance: Output:

2.Multilevel inheritance: InĀ multilevel inheritance, a derived class is created from another derived class, and that derived class can be derived from a base class or any other derived class. The final derived class can access the members of its immediate parent as well as all the ancestor classes before it.

Example:

Example: Output:

Questions: For single inheritance, create two classes, one with addition(parent class) and one with subtraction(child class), and in the child class print the result of both addition and subtraction. For Multilevel inheritance, Write a program where base class gets the name of a student , the immediate derived class gets three subjects marks and then stores, where the second derived class stores the percentage and total of the student and prints the all details above neatly.

1. Single inheritance:

1. Single inheritance: Output:

Multilevel inheritance:

Multilevel inheritance: Output:
Tags