+ 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 ????

24th Dec 2016, 7:22 AM
Hasan Teymoori
Hasan Teymoori - avatar
4 Respostas
+ 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
24th Dec 2016, 7:33 AM
Wen Qin
Wen Qin - avatar
+ 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
24th Dec 2016, 9:03 AM
Vladislav
Vladislav - avatar
+ 1
Cat class has access to all Animal members marked as public and protected
24th Dec 2016, 7:29 AM
Vladislav
Vladislav - avatar
+ 1
how its possible ?? the Cat arrived from FourLegs not animal.. how Cat access the Animal members?
24th Dec 2016, 8:50 AM
Hasan Teymoori
Hasan Teymoori - avatar