+ 1
Inherit base member???
I have a base class: Animal and I have a arrived class: FourLegs and FourLegs is the base class for another class by name : Cat so I have 3 class that Animal is base for Four legs, and FourLegs is base for Cat.. my question : can i access the all member's animal class by the Cat objects ????
4 ответов
+ 4
private << No one but the 'founder' ( or parent/struct)can access it
public << everyone can access it
protected << Only those inside the range of the 'founder'(parent/struct) can access it
+ 2
"that Animal is base for Four legs, and FourLegs is base for Cat"
As I understand
class Animal
{
public int a;
}
class FourLegs : Animal
{
public int b;
}
class Cat : FourLegs
{
}
//somewhere
Cat cat;
cat.a = 5;
cat.b 6;
FourLegs inherits a variable from its base class
and Cat inherits b variable from FourLegs and a from Animal because it is base in 2nd generation
+ 1
Cat class has access to all Animal members marked as public and protected
+ 1
how its possible ?? the Cat arrived from FourLegs not animal.. how Cat access the Animal members?