
Inheritance 245
If tomorrow a new requirement pops up to add one more float variable z into class A, it is
recommended to inherit class B from A as follows:
#include<iostream>
using namespace std;
class B: public A
{
float z;
public:
B(float a, float b,float c):A(a,b,c){z=c;}
void Display(){ base:: Display(); cout<<z<<endl; }
}
The disadvantages of inheritance are as follows:
(i) If the public or protected member(s) of a base class are changed and these meth-
ods are already used by a derived class or its object, it gets affected. For example, if
DisplayData member function in a base class is changed, the following code already
written gets affected. ...