Classes & Objects · Question 10 · Medium
Three classes in a chain each extend fee() using super(). What does the last class return?
class Base:
def fee(self):
return 1000
class Hostel(Base):
def fee(self):
return super().fee() + 500
class AC(Hostel):
def fee(self):
return super().fee() * 2
print(AC().fee())
- 3000
- 2000
- 2500
- 1500
Answer and explanation
Answer: A. 3000
Explanation: AC.fee calls Hostel.fee, which calls Base.fee and gets 1000, then adds 500 to make 1500. AC doubles that result to 3000.
Previous: The child class Student defines its own __init__ and does not call the… · Next: The Point class defines __eq__. What do == and is give for two separately…
Practise classes & objects
Try a fresh set of classes & objects questions with an explanation after every answer, free and without signing up: Classes & Objects practice. Or sit a full placement mock test.
More classes & objects questions
- The method on() in the Lamp class is written without a self parameter. What…
- wheels is a class attribute of Car, and it is then assigned through one…
- The child class Student defines its own __init__ and does not call the…
- The Point class defines __eq__. What do == and is give for two separately…
- A class method reads a counter that __init__ increases on the class. What is…
- fahrenheit is declared with @property and is accessed without brackets. What…
- What is the key difference between a method marked @classmethod and one marked…
- B is a child of A. What do isinstance, a direct type comparison and issubclass…
- D inherits from both B and C, and B and C both inherit from A. Which who()…
- Every class in this diamond calls super().go(). What string does D().go() build?
More python practice
Exceptions & Files · Built-ins & Standard Library · Variables, Types & Operators · Python Strings · Lists & Tuples · Dictionaries & Sets · Conditions & Loops · Functions & Scope
LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge