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 Vehicle: | AThe general class is the child of a specialised class. The specialised Student should inherit from the general Person. | |
| 2class Car(Vehicle): | Bclass Animal: def __init__(self, name, age): | |
| 3Spotting common features: Dog and Cat both store a name and an age, so these shared attributes belong in a general Animal class | Cclass Dog(Animal): def __init__(self, name, age): super().__init__(name, age) | |
| 4Reducing repeated code: a specialised class calls the general parent class to set up the shared attributes instead of copying them | DA specialised class that reuses what Vehicle provides and only adds its own extra features | |
| 5class Student: def __init__(self, name): self.name = name class Teacher: def __init__(self, name): self.name = name | EA general parent class holding the attributes and methods shared by Car, Truck and Bike | |
| 6class Person(Student): def __init__(self, name): self.name = name | FBoth classes repeat the same name attribute. Generalisation would move it into a general Person parent class. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
generalisation — Finding the attributes and methods that several classes share and moving them into one more general parent class, so the code is not repeated in each specialised class.class Vehicle:
def start(self):
print("Engine on")class Vehicle:
wheels = 4
class Car(Vehicle): passclass Bike(Vehicle):
pass
Bike().start()class Animal:
def eat(self): print("Eating")
class Cat(Animal): passclass Pet: legs = 4
class Dog(Pet): pass
print(Dog().legs)