LearnFrenzy
Sign in Take a free test

Inheritance and Polymorphism · Exercise 1 of 4

Inheritance and Polymorphism Inheritance and Polymorphism MCQ

  • 15 questions
  • Page 2 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Fifteen multiple-choice questions on Python inheritance and polymorphism: overriding, super(), multilevel and multiple inheritance, the MRO, abstract classes, duck typing and operator overloading. Pick an option to check your answer instantly.

Question 11 Easy

Which method makes a + b work for objects of your class?

A __add__
B __plus__
C __sum__
D __concat__
Question page & discussion
Question 12 Hard

Why does sum([Money(1), Money(2)]) need __radd__?

A sum starts with 0, so it computes 0 + Money(1), which needs Money.__radd__
B sum adds from right to left
C __add__ is ignored by sum
D It does not need it
Question page & discussion
Question 13 Hard

What should __add__ return when it does not support the other operand's type?

A None
B False
C raise NotImplementedError
D NotImplemented
Question page & discussion
Question 14 Medium

A subclass defines __init__ but never calls super().__init__(). What is the usual consequence?

A Python calls the parent __init__ automatically
B SyntaxError
C Attributes the parent would set are missing, leading to AttributeError later
D The object cannot be created
Question page & discussion
Question 15 Medium

A Car needs an Engine. Which design is usually better?

A Inheritance: class Car(Engine)
B Multiple inheritance: class Car(Engine, Wheel)
C Composition: give Car an engine attribute (a car has an engine)
D Make Engine an abstract class of Car
Question page & discussion
Up next · Exercise 2Predict the Output15 questions

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links