1. Learn
  2. /
  3. Courses
  4. /
  5. Object-Oriented Programming in Python

Exercise

Method inheritance

Inheritance is powerful because it allows us to reuse and customize code without rewriting existing code. By calling methods of the parent class within the child class, we reuse all the code in those methods, making our code concise and manageable.

In this exercise, you'll continue working with the Manager class that is inherited from the Employee class. You'll add new data to the class, and customize the give_raise() method from Chapter 1 to increase the manager's raise amount by a bonus percentage whenever they are given a raise.

A simplified version of the Employee class, as well as the beginning of the Manager class from the previous lesson is provided for you in the script pane.

Instructions 1/2

undefined XP
    1
    2

Add a constructor to Manager that:

  • accepts name, salary (default 50000), and project (default None)
  • calls the constructor of the Employee class with the name and salary parameters,
  • creates a project attribute and sets it to the project parameter.