I have the following class declarations:
class human
{
public:
void msg(){cout<<"I am human\n";}
};
class John:public human
{
public:
void msg(){cout<<"I am a John\n";}
};
As it is clear the class John and human both have a function msg(). Clearly , the class John is inheriting resources from human. Now when I create an object of the derived class and call msg():
John a;
a.msg();
The output is :
I am John
But doesnt John inherit msg() from human?
Also is there a way to access msg() of human by using an object of the derived class?
EDIT:
Yup calling the function like so will help me
a.human::msg()
Another question :
Also if I modify the class like so:
class human
{
protected:
void msg(){cout<<"I am human\n";}
};
class John:public human
{
public:
void msg(){cout<<"I am a John\n";}
};
Now how can I access the msg() of human.