Saturday 11 April 2015

Overloaded Function in Base and Derived classes


#include <iostream.h>
class A
{
char ch;
public:
A(char c)
{
ch = c;
}
void show(void)
{
cout<<ch;
}
};
class B
{
char ch;
public:
B(char b)
{
ch = b;

}
void show(void)
{
cout<<ch;
}
};
class C:public A, public B
{
char ch;
public:
C(char c1, char c2, char c3):A(c1), B(c2)
{
ch = c3;
}
void show(void) // overloaded function in derived class
{
A::show();
B::show();
cout<<ch;
}
};
void main()
{
C obj(‘a’,’b’,’c’);
Cout<<”A class show”;
// Obj.A::show();
Cout<<”B class show”;
// Obj.B::show();
Obj.show //derived class show will be executed
}


No comments:

Post a Comment