If there is a superclass named A and a subclass named B, which one of the presented invocations should you put instead of the comment?
class A: def __init__(self): self.a = 1 class B(A): def __init__(self): # Put selected line here. self.b = 2
- __init__()
- A.__init__(self)
- A.__init__(1)
- A.__init__()
Explanation: The example shows a superclass named A, which defines its own constructor. The A class is then used as a base to create a subclass named B, which defines its own constructor. The B class constructor should now invoke the constructor from the A class, which can be done like this: A.__init__(self).
More Questions: Python Essentials 2 – Module 3 Test
Please login or Register to submit your answer