We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Inheritance Hierarchy

There is no (technical) limit to how deeply we can nest an inheritance tree. For example:

Tiger inherits from Feline inherits from Animal inherits from LivingThing.

That said, be careful! New programmers often get carried away. You should never think to yourself:

"Well most wizards are elves... so I'll just have Wizard inherit from Elf"

A good child class is a more specific type of its parent class.

Assignment

Let's add a new game unit: Crossbowman. A crossbowman is always an archer, but not all archers are crossbowmen. Crossbowmen have several arrows, but they have an additional method: triple_shot().

      • Use 3 arrows
      • Get the name of the target Human using its methods
      • Return the string TARGET was shot by 3 crossbow bolts where TARGET is the name of the Human that was shot