Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1class Dog(Animal): | ADog is a child (sub) class that inherits the attributes and methods of the parent class Animal | |
| 2class Car(Vehicle): pass | BThe parent and child are the wrong way round. Dog is an Animal, so Dog should be the child: class Dog(Animal): | |
| 3Is-a relationship: a Student is a kind of Person, so Student is the child class | Cclass Student(Person): | |
| 4Reuse of code: a child object can call a method written only in the parent class | DCar reuses everything from Vehicle without writing any new code, because a Car is a Vehicle | |
| 5class Animal(Dog): | EPython has no inherits keyword. The parent class must go in brackets: class Teacher(Person): | |
| 6class Teacher inherits Person: | Fpet = Dog() pet.eat() |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
class Child(Parent): — Inheritance: the child (sub) class reuses the parent (super) class's attributes and methods and can add or change its own, showing an is-a relationship.class Animal:
pass
class Dog(Animal):class Bird(Animal):
def speak(self):
print("Tweet")rex = Dog()
print(isinstance(rex, Animal))class Dog(Animal): pass
print(issubclass(Dog, Animal))class Animal: pass
class Dog(Animal): pass
class Puppy(Dog): pass