16.17. Group Work - Working with Multiple Classes

It is best to use a POGIL approach with the following. In POGIL students work in groups on activities and each member has an assigned role. For more information see https://cspogil.org/Home.


If you work in a group, have only one member of the group fill in the answers on this page. You will be able to share your answers with the group at the bottom of the page.

Learning Objectives

Students will know and be able to do the following.

Content Objectives:

16.17.1. Inheritance

One class can inherit attributes and behavior from another class. The class that is inherited from is called the parent or base class. The one that is inheriting is called the child or derived class.

Run the following code

Look at the classes defined above. Then answer the following questions.

Drag the blocks from the left and put them in the correct order on the right to define two classes: Car and SportsCar that inherits from Car. Add an __init__ method to the Car class that takes a make and sets the current object’s make. Add a __str__ method to the Car class and return a string with the make. Add an __init__ method to the SportsCar class that calls the parent class __init__ method.

Look at the code below and answer the following questions.

Run the following code

Modify the code above to add a __str__ method to the Greeter class that returns the self.message and run the code again.

16.17.2. Overriding an Inherited Method

The child class can override an inherited method. This means it provides the same method name and parameter list as an inherited method.

Run the following code

If you worked in a group, you can copy the answers from this page to the other group members. Select the group members below and click the button to share the answers.

The Submit Group button will submit the answer for each each question on this page for each member of your group. It also logs you as the official group submitter.

You have attempted of activities on this page