Session Ready
Exercise

Inheritance of class attributes

In the beginning of this chapter, you learned about class attributes and methods that are shared among all the instances of a class. How do they work with inheritance?

In this exercise, you'll create subclasses of the Player class from the first lesson of the chapter, and explore the inheritance of class attributes and methods.

The Player class has been defined for you. Recall that the Player class had two class-level attributes: MAX_POSITION and MAX_SPEED, with default values 10 and 3.

Instructions 1/2
undefined XP
  • 1
  • 2
  • Create a class Racer inherited from Player,
  • Assign 5 to MAX_SPEED in the body of the class.
  • Create a Player object p and a Racer object r (no arguments needed for the constructor).

Examine the printouts carefully. Next step is a quiz!