Thursday, 15 August 2013

How to answer inheritance

How to answer inheritance

p`class Animal/p p{private:/p pstring sound;/p pint warmblooded;/p
ppublic:/p pAnimal(string s, int warm)/p p{ sound=s;/p
pwarmblooded=warm;/p p}/p pvoid print()/p p{ coutlt; pif(warmblooded==1)/p
pcoutlt;lt;i'm warm bloodedlt; pelse/p pcoutlt;lt;i'm cold bloddedlt; p}/p
p};/p pclass Cat : protected Animal/p p{ int foodintake;/p pstring name;/p
ppublic:/p pvoid print()/p p{ coutlt;lt;"Name :"lt; pcoutlt;lt;"Food
intake:"lt; pAnimal::print(); }/p pCat(string n, int f) :
Animal("meoooow",1)/p p{ name = n;/p pfoodintake = f;/p p}/p p};`/p p1)Is
print() member function of Animal class accessible to Cat class? Justify
your answer./p p2)Is sound data member of Animal class accessible to Cat
class? Justify your answer./p

No comments:

Post a Comment