If I have a class, class Animal.
And I have a class Dog and a class Cat both inheriting Animal.
Cat can call methods inside Animal. But can Cat call methods of Dog?
If I have a class, class Animal.
And I have a class Dog and a class Cat both inheriting Animal.
Cat can call methods inside Animal. But can Cat call methods of Dog?
The methods defined in a superclass are accesible to any subclass. But "sister" classes cannot access the (private) methods of one another.
So if your classes
Cat
andDog
inherit fromAnimal
, then bothCat
andDog
objects can call methods fromAnimal
, but they cannot (must not) access the methods of each other.I'm afraid that... no.
Cat
cannon invokeDog
methods.Inheritance allows to "view" parents (
public
/protected
if you are using Java) methods inside child classes, but not inside siblings classes.Obviosly if
Cat
has an instance ofDog
as property (I don't know why it should have...) it can callpublic
methods of thatDog
instance.