Objects 3 - Inheritance


examples


Classwork

An educational game about a zoo includes elephants, penguins, and zookeepers.  Each animal is assigned a zookeeper, and has a name, and a weight, and can eat, move, and sleep.  Zookeepers have a name and a salary. 

Use inheritance to create classes representing this situation, thinking about which things have an inheritance relationship and which should just use instance variables.  Methods for behaviors can just print what they are doing. In at least one case, have a subclass override a method, and in at least one case, have a subclass add an instance variable or method its superclass didn't have, to better reflect what the classes represent (you don't have to be perfectly zoologically accurate, but it should make sense).