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; }
0 comments:
Post a Comment