Session 19 Preparation — Videos, Reading and Quizzes
There is no required Quiz for session 19 preparation.
We strongly recommend that, after reading each section, you do the following Self-check exercises,
and check your answers against those given at the end of the chapter.
If there are answers that you do not understand, please ask about them at the beginning of the Session 19 class.
(page 511) 1, 2, 3, 5 (516) 6, 7, 8 (520) 13 (523-524) 16, 17, 18
- Defining Classes and Objects
- Textbook reading: Sections
10.1-10.4 — Inheritance basics (pages 508-524).
You saw many of these ideas "by example" in your Session 18
class (Acrobats example); now it is time to look at the details.
- As you read, focus your attention on:
- Inheritance hierarchies in Section 10.1.
- Consider the Vehicle and Question hierarchies on pages 508 and 509.
Note that the upward-pointing arrows in each diagram could be read "IS-A", as in "a Sedan is a Car".
- Be sure to understand the code in questions.py and
questiondemo1.py, because code in later sections
of this chapter will be based on it.
- Be sure to read Programming Tip 10.1 on page 511.
- Special Topic 10.1 describes the __repr__
method, which we saw in Session 16 for the Point
and Fraction classes.
- Implementing Subclasses in Section 10.2
- All instance variables and methods of the superclass are inherited by the subclass.
- Inherited methods may be "used as is", overridden, or partially overridden (use the
superclass method, but also do some other stuff).
Pay special attention to Syntax 10.1 on page 514 and
Figure 6 on page 515, along with the textbook's explanations of these.
-
Common Errror 10.1: Confusing Super- and
Subclasses (pages 516-517). Isn't a subclass
more "super" than its superclass?
- Calling the superclass constructor (section
10.3). Pay special attention to the use of
super().__init__()
We used this in the Acrobats exercise in Session 18.
- Overriding methods from the superclass (section 10.4).
The words are important, but understanding the code on pages 522-523 is
most critical.