Inheritance Single and Multilevel inheritance.pptx
rupanaveen24
8 views
17 slides
Aug 30, 2025
Slide 1 of 17
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
About This Presentation
C++
Size: 1.15 MB
Language: en
Added: Aug 30, 2025
Slides: 17 pages
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.