C++ Program to add two numbers using multilevel inheritance
In this program, You will learn how to add two numbers using multilevel inheritance in C++.
#include<iostream>
using namespace std;
int main(){
//Statement
}
Example: How to add two numbers using multilevel inheritance in C++
#include<iostream>
using namespace std;
class First {
public:
int a, b, s;
void input() {
cout << "Enter two numbers:";
cin >> a>>b;
}
};
class Second : public First {
public:
void add() {
s = a + b;
}
};
class Third : public Second {
public:
void display() {
cout << "Sum is:" << s;
}
};
int main() {
Third th;
th.input();
th.add();
th.display();
return 0;
}
Output:
Enter two numbers:10 20
Sum is:30