
468 Inheritance
{
cout<<“a1=”<<a1 <<“a2=”<<a2 <<“a3=”<<a3 <<“a4=”<<a4;
}
};
int main()
{
clrscr();
A4 a;
a.get(); // Reads data
a.put(); // Displays data
return 0;
}
OUTPUT
Enter values for a1, a2,a3 and a4 : 5 8 7 3
a1= 5 a2 = 8 a3 = 7 a4 = 3
Explanation: In the above program, the classes A1, A2, A3, and A4 are declared, and
each contains one protected member variable. The class A4 has two member functions
get() and put(). The get() function reads integers through the keyboard. The put() func-
tion displays the contents of the member variables on the screen. The classes A2 and A3 are
derived from class A1. While deriving these two classes, ...