Consider the program below.
class Vehicle:
def __init__(self, reg, wheels=4):
self.reg = reg
self.wheels = wheels
def describe(self):
return self.reg + " has " + str(self.wheels) + " wheels"
class Motorbike(Vehicle):
def __init__(self, reg):
super().__init__(reg, 2)
self.sidecar = False
def describe(self):
return super().describe() + " and no sidecar"
v = Vehicle("AB12")
m = Motorbike("XY99")
print(v.describe())
print(m.describe())
print(isinstance(m, Vehicle))(a) State the output of the program. [3]
(b) Identify the method, other than the constructor __init__, that is overridden in Motorbike. [1]
(c) State the purpose of super().__init__(reg, 2). [1]
- (a)
AB12 has 4 wheels(1) XY99 has 2 wheels and no sidecar(1)True(1)- (b)
describe(1) - (c) Calls the superclass constructor so the inherited attributes (reg and wheels) are initialised, here with wheels set to 2(1)
- Answer: (a) AB12 has 4 wheels / XY99 has 2 wheels and no sidecar / True (b) describe (c) runs Vehicle's constructor
- Examiner tip: Boolean outputs are written as True with a capital T.