simple inheritance question

  • Thread starter Thread starter relient
  • Start date Start date
R

relient

Hi, I have three classes: Animal, Dog and Cat. Dog inherits from Animal
and Cat inherits from Dog. My question is: is Cat now also a Animal
even though it didn't inherit directly from Animal?
 
Hi
Ya, the derived class is type of all its base classes and inherits all
of state and behaivour of all of its parents.

A.Hadi
 
relient said:
Hi, I have three classes: Animal, Dog and Cat. Dog inherits from Animal
and Cat inherits from Dog. My question is: is Cat now also a Animal
even though it didn't inherit directly from Animal?

Who knows? Since you can only make a cat inherit from a dog by some rather
extreme genetic engineering it's difficult to say.

If, on the other hand, Labrador inherited from Dog then it would be an
Animal.
 
I forwarded this onto the developers group here, this is one of the
repsonses i got back:

Fur what it's worth...

If I inherited a cat, I would exchange it for a dog because I prefer
dogs.
 
Mark Harris said:
I forwarded this onto the developers group here, this is one of the
repsonses i got back:

Fur what it's worth...

aaaaagh that's an awful pun.
 
"relient" <[email protected]> a écrit dans le message de (e-mail address removed)...

| Hi, I have three classes: Animal, Dog and Cat. Dog inherits from Animal
| and Cat inherits from Dog. My question is: is Cat now also a Animal
| even though it didn't inherit directly from Animal?

Inheritance implies an "is a" relationship. By inheriting Dog from Animal,
you are saying that a Dog "is" an Animal. Inheriting Cat from Dog means that
a Cat "is" a Dog, which "is" also an Animal.

Apart from the fact that a Cat isn't really a Dog shouldn't spoil the
illusion :-))

Seriously though, You would correctly inherit both Cat and Dog from Animal
and then you could inherit from Dog to give you different breeds like
Alsatian, Spaniel, etc.

Joanna
 
Back
Top