Unit 4: More on OOP concepts - Subjective Questions

ECAP776 • Practice Questions with Detailed Answers

20 questions

1

Define function overloading. Does Python support traditional function overloading based on parameter types or parameter count?

2

Explain how default arguments can be used to simulate function overloading in Python, with an example.

3

Describe how *args and **kwargs help implement flexible or overloaded-like functions in Python.

4

Compare the use of default arguments, *args, and explicit type checking as alternatives to function overloading in Python.

5

What is functools.singledispatch? Explain how it provides type-based function dispatch in Python.

6

Explain operator overloading in Python. Why is it useful in user-defined classes?

7

Design a Vector2D class that overloads the + operator. Explain what happens when two vector objects are added.

8

Distinguish among __add__(), __radd__(), and __iadd__() in Python operator overloading.

9

Explain the purpose of returning NotImplemented from an overloaded operator method. How does it differ from raising NotImplementedError?

10

Describe how comparison operators can be overloaded in Python. Include the roles of __eq__() and __lt__().

11

What is the relationship between __eq__() and __hash__() when operator overloading is used for value equality?

12

Explain how the @functools.total_ordering decorator reduces the work needed to overload ordering operators.

13

Differentiate between operator overloading and method overriding in Python.

14

Define method overriding and illustrate it using a base class and a derived class.

15

Explain the role of super() in an overridden method. Why is it preferable to directly naming the parent class in many situations?

16

Explain how Python's method resolution order (MRO) affects method overriding in multiple inheritance.

17

Describe cooperative method overriding in multiple inheritance and state the conditions required for it to work correctly.

18

How do abstract methods relate to method overriding? Explain using the abc module.

19

Compare method overriding with simply adding a new method to a subclass. Discuss interface compatibility.

20

Develop a Python example that combines method overriding and operator overloading, and explain how both forms of polymorphism operate.