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.

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.

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

You have attempted of activities on this page