Inheritance question

Hello there fellow geek's.

So Im trying to learn thw concept of inheritance and Im wrighting som simple classes of animals. What I have so far is the base class Animal and some sub classes dog, bird, fish / shark and so on. But now to the thig that I wonder about, lets say I want to add 2 other class's "Meateater" and "vegetarian", where in the hierarki should I put them, befor Animal, or after? cuz not all animals are meateaters. Or should Meateater and Vegetarian be there own sub classes?

Best regards.
Between abstract Animal and concrete subclass. Also remember that there is also Omnivores. Think how to implement that.
The terminology you want is Carnivore and Herbivore,and probably add Omnivore. And based on your derived classes from animal, I would put the type of eating habits as member variables. Some birds eat meat some don't, some fish eat meat,some don't. So you can't have animal types derived from diet types. And if you did do a diet class I cant think much of anything that would be in it.
Last edited on
Lets say I make an object shark, then it has to inherit from fish, and Carnivore to ?
Topic archived. No new replies allowed.