Single inheritance in C++ OOP, Syntax of single inheritance, Example of single inheritance
In this tutorial, we will learn about the followings;
- Single inheritance in C++ OOP
- The syntax of single inheritance in C++ OOP
- Example of single inheritance in C++ OOP
What is single inheritance?
In single inheritance child class is derived from only and only one parent class.
Syntax to inherit the class from the parent class in single inheritance?
|1||class child_class_name : Access_specifier Parent_class_name|
|3||Body of the class;|
Example of singe inheritance
using namespace std;
class child : public sum
Line 9 shows single inheritance where the child has only one parent as a sum. Variable declaration of n1 and n2 in line 6 and 7 is inherited from the parent class and used in child class”show”.
|Test Your Understandings|
1.In single inheritance multiple child can have multiple parent classes? YES / NO
2.class child_class_name : Access_specifier parent_class_name is the correct syntax for creating child class? YES / NO.