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

Connected

Exercise

Customize a subclass

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 a constructor that builds on the Employee constructor, taking an additional argument where you can specify the project that the manager is working on.

A simplified version of the Employee class, as well as the beginning of the Manager class you previously created, has been provided for you in script.py.

Instructions

100 XP
  • Add a constructor to Manager that accepts name, salary (default value of 50000), and project (default value of None).
  • Inside the Manager constructor, call the constructor of the Employee class providing the three arguments defined in the constructor of the parent class.
  • Use self to assign the relevant attribute to the project argument.