Sunday, 1 February 2015

Multiple inheritance in C++

Structure of the Problem Requirements 

Deriving directly from more than one class is usually called multiple inheritance. The example contains a parent class that is called calculator and they have two methods add() and subtract(). The Parent class has two more child classes which are further inherited.

Source Code

#include <iostream>
using namespace std;

class calculator
{
 public:
void add()
{
cout<<"Add method \n\n ";
}
void subtract()
{
cout<<"\n Subtract Method \n\n ";
}
};
class add : public calculator //add class inherited calculator
{
};
class Subtract : public add //subtract class inherited add and further the caluclulotr
{//subtract class be can derived from a derived class which is known as multilevel inhertiance
};
int main()
{
Subtract s;
add a;
cout<<"\n\n\n\t ********** MULTILEVEL INHERITANCE ********** \n\n\n";
a.subtract();
s.subtract();
return 0;
}

Output of the Program

Multiple inheritance in C++

Share it Please
asad

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.

0 comments:

Post a Comment