C++ Multiple, Multilevel and Hierarchical Inheritance - learnit

Home Top Ad

Post Top Ad

Saturday, January 8, 2022

C++ Multiple, Multilevel and Hierarchical Inheritance

C++ Multiple, Multilevel and Hierarchical Inheritance

In this tutorial, we will learn about various inheritance models in C++ programming: Examples of multiple, multilevel, and hierarchical inheritance.


Inheritance is a key characteristic of an object-oriented programming language. It enables software developers to create a new class from an existing one. The features of the base class are passed down to the derived class (existing class).


There are various models of inheritance in C++ programming.


C++ Multilevel Inheritance


In C++ programming, you can derive a class not only from the base class, but also from the derived class. This type of inheritance is referred to as multilevel inheritance.


class myclass{
.......
};
class myclass1:public myclass{
..........
};


Here, class MyClass1 is derived from the base class MyClass

Example

#include<stdio.h>
#include<conio.h>
#include<iostream>
using namespace std;
class myclass{
public:
myclass(){
cout<<"Hello Knowledge Education Cambodia";
}
};
class myclass1{
public:
myclass1(){
cout<<endl;
cout<<"Hello Reanits";
}
};
class myclass2:public myclass,public myclass1 {};
int main(){
myclass2 obj;
}


Noteped
In this program, class MyClass2 is derived from base class MyClass and MyClass1 .
The Obj object of class MyClass2 is defined in the Main function.


Please Watching My Video is Below

No comments:

Post a Comment

Post Top Ad