Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.

Unit 4 MCQs More on OOP concepts

ECAP776 60 questions. Pick an option to check it.

Read the notes Subjective questions

0 of 60 answered 0 right 0 wrong , 60 left

  1. Question 1 of 60 Function overloading Easy

    What does function overloading generally mean?

  2. Question 2 of 60 Function overloading Easy

    Does Python directly support traditional function overloading based only on parameter lists?

  3. Question 3 of 60 Function overloading Easy

    What happens when multiple functions with the same name are defined in the same Python scope?

  4. Question 4 of 60 Function overloading Easy

    Which Python feature can imitate function overloading by allowing an argument to be omitted?

  5. Question 5 of 60 Function overloading Easy

    Which parameter syntax allows a Python function to accept a variable number of positional arguments?

  6. Question 6 of 60 Function overloading Easy

    What is a common benefit of function overloading?

  7. Question 7 of 60 Function overloading Easy

    Which standard-library decorator supports dispatch based on the type of the first argument?

  8. Question 8 of 60 Operator overloading Easy

    What is operator overloading in Python?

  9. Question 9 of 60 Operator overloading Easy

    Which special method overloads the + operator?

  10. Question 10 of 60 Operator overloading Easy

    Which special method overloads the - operator?

  11. Question 11 of 60 Operator overloading Easy

    Which special method is associated with the == operator?

  12. Question 12 of 60 Operator overloading Easy

    Which special method is called for the * operator?

  13. Question 13 of 60 Operator overloading Easy

    What is another common name for methods such as __add__() and __sub__()?

  14. Question 14 of 60 Operator overloading Easy

    If a + b is evaluated and a defines __add__(), which call does Python try?

  15. Question 15 of 60 Operator overloading Easy

    Which built-in type demonstrates + with both arithmetic and concatenation behavior?

  16. Question 16 of 60 Method overriding Easy

    What is method overriding?

  17. Question 17 of 60 Method overriding Easy

    Which object-oriented concept is required for method overriding?

  18. Question 18 of 60 Method overriding Easy

    When an overridden method is called on a child-class object, which version normally runs?

  19. Question 19 of 60 Method overriding Easy

    Which function can a child class use to call the parent class implementation?

  20. Question 20 of 60 Method overriding Easy

    What does method overriding help a child class do?

  21. Question 21 of 60 Function overloading Medium

    What does the following code print?

    def calculate(a, b):
    return a + b

    def calculate(a, b, c):
    return a + b + c

    print(calculate(2, 3))

  22. Question 22 of 60 Function overloading Medium

    Which definition best simulates overloading a function so that it can add either two or three numbers?

  23. Question 23 of 60 Function overloading Medium

    What is the output of this code?

    def total(*values):
    return sum(values)

    print(total(2, 4, 6))

  24. Question 24 of 60 Function overloading Medium

    A function must format either one name or a first name followed by a last name. Which signature is most suitable?

  25. Question 25 of 60 Function overloading Medium

    Given the function below, which call returns 6?

    def multiply(a, b=2, c=1):
    return a b c

  26. Question 26 of 60 Function overloading Medium

    Which approach provides type-based function dispatch using Python's standard library?

  27. Question 27 of 60 Function overloading Medium

    What does this function return for describe("Python")?

    def describe(value):
    if isinstance(value, str):
    return len(value)
    return value * 2

  28. Question 28 of 60 Operator overloading Medium

    Which special method should a class implement to customize the behavior of the + operator?

  29. Question 29 of 60 Operator overloading Medium

    What does the following code print?

    class Score:
    def init(self, value):
    self.value = value

    def add(self, other):
    return Score(self.value + other.value)

    result = Score(7) + Score(5)
    print(result.value)

  30. Question 30 of 60 Operator overloading Medium

    A Vector class should support 3 * vector when it already supports vector * 3 through __mul__. Which method should normally be added?

  31. Question 31 of 60 Operator overloading Medium

    What should __add__ usually return when it cannot handle the type of the other operand?

  32. Question 32 of 60 Operator overloading Medium

    Which special method is invoked by a == b to test value equality?

  33. Question 33 of 60 Operator overloading Medium

    What is printed by the following code?

    class Box:
    def init(self, items):
    self.items = items

    def len(self):
    return len(self.items) * 2

    print(len(Box([1, 2, 3])))

  34. Question 34 of 60 Operator overloading Medium

    What is the main behavioral difference between __add__ and __iadd__?

  35. Question 35 of 60 Method overriding Medium

    What does this code print?

    class Animal:
    def speak(self):
    return "sound"

    class Dog(Animal):
    def speak(self):
    return "bark"

    pet = Dog()
    print(pet.speak())

  36. Question 36 of 60 Method overriding Medium

    What is printed by this code?

    class Parent:
    def message(self):
    return "Parent"

    class Child(Parent):
    def message(self):
    return super().message() + " Child"

    print(Child().message())

  37. Question 37 of 60 Method overriding Medium

    Which condition is essential for a subclass method to override an inherited instance method?

  38. Question 38 of 60 Method overriding Medium

    What does the following code print?

    class Report:
    def title(self):
    return "General"

    class SalesReport(Report):
    pass

    print(SalesReport().title())

  39. Question 39 of 60 Method overriding Medium

    Consider the classes below. What does process(EmailNotification()) return?

    class Notification:
    def send(self):
    return "default"

    class EmailNotification(Notification):
    def send(self):
    return "email"

    def process(item):
    return item.send()

  40. Question 40 of 60 Method overriding Medium

    What is the result of calling Manager().work()?

    class Employee:
    def work(self, hours=4):
    return hours

    class Manager(Employee):
    def work(self, hours=4):
    return super().work(hours) * 2

  41. Question 41 of 60 Function overloading Hard

    What does the following program print?

    def f(x):
    return x + 1

    g = f

    def f(x, y=3):
    return x * y

    print(g(4), f(4))

  42. Question 42 of 60 Function overloading Hard

    What is printed at runtime?

    from typing import overload

    @overload
    def convert(x: int) -> str: ...

    @overload
    def convert(x: str) -> int: ...

    def convert(x):
    return x * 2

    print(convert("7"), convert(7))

  43. Question 43 of 60 Function overloading Hard

    Which handler is selected by this singledispatch call?

    from functools import singledispatch

    @singledispatch
    def label(x):
    return "object"

    @label.register(int)
    def _(x):
    return "int"

    print(label(True))

  44. Question 44 of 60 Function overloading Hard

    What is the result of the final call?

    from functools import singledispatch

    @singledispatch
    def combine(a, b):
    return "base"

    @combine.register(int)
    def (a, b):
    return "int:" + type(b).name

    @combine.register(str)
    def
    (a, b):
    return "str:" + type(b).name

    print(combine(1, "x"))

  45. Question 45 of 60 Function overloading Hard

    What does this program print?

    from functools import singledispatchmethod

    class Renderer:
    @singledispatchmethod
    def render(self, value, mode):
    return "base"

    @render.register
    def _(self, value: int, mode):
    return "int"

    print(Renderer().render(True, "brief"))

  46. Question 46 of 60 Function overloading Hard

    What is printed by the following class definition?

    class Calculator:
    def calc(self, x):
    return x * 10

    @staticmethod
    def calc(x, y=1):
    return x + y

    print(Calculator().calc(3))

  47. Question 47 of 60 Operator overloading Hard

    What does this program print?

    trace = []

    class A:
    def add(self, other):
    trace.append("A.add")
    return "left"

    class B(A):
    def radd(self, other):
    trace.append("B.radd")
    return "right"

    print(A() + B(), trace)

  48. Question 48 of 60 Operator overloading Hard

    What is the outcome of x + x?

    log = []

    class X:
    def add(self, other):
    log.append("add")
    return NotImplemented

    def radd(self, other):
    log.append("radd")
    return 9

    x = X()
    try:
    x + x
    except TypeError:
    print(log)

  49. Question 49 of 60 Operator overloading Hard

    What does the final statement print?

    class Box:
    def init(self, value):
    self.value = value

    def add(self, other):
    return Box(self.value + other)

    a = Box(2)
    b = a
    a += 3
    print(a.value, b.value, a is b)

  50. Question 50 of 60 Operator overloading Hard

    What happens when the final line executes?

    class Key:
    def init(self, value):
    self.value = value

    def eq(self, other):
    return isinstance(other, Key) and self.value == other.value

    k = Key(3)
    print(hash(k))

  51. Question 51 of 60 Operator overloading Hard

    What is printed by this comparison?

    log = []

    class A:
    def lt(self, other):
    log.append("A.lt")
    return "left"

    class B(A):
    def gt(self, other):
    log.append("B.gt")
    return "right"

    print(A() < B(), log)

  52. Question 52 of 60 Operator overloading Hard

    What are the values of events and result.tag?

    events = []

    class Token:
    def init(self, tag):
    self.tag = tag

    def bool(self):
    events.append("bool " + self.tag)
    return False

    class N:
    def init(self, name):
    self.name = name

    def lt(self, other):
    tag = self.name + other.name
    events.append("lt " + tag)
    return Token(tag)

    result = N("a") < N("b") < N("c")

  53. Question 53 of 60 Operator overloading Hard

    What does the following program print?

    class Bag:
    def getitem(self, index):
    if index >= 3:
    raise IndexError
    return (4, 6, 8)[index]

    print(6 in Bag(), 5 in Bag())

  54. Question 54 of 60 Method overriding Hard

    What does D().m() return under Python's method resolution order?

    class A:
    def m(self):
    return ["A"]

    class B(A):
    def m(self):
    return ["B"] + super().m()

    class C(A):
    def m(self):
    return ["C"] + super().m()

    class D(B, C):
    pass

  55. Question 55 of 60 Method overriding Hard

    How does changing C.m affect the result?

    class A:
    def m(self):
    return ["A"]

    class B(A):
    def m(self):
    return ["B"] + super().m()

    class C(A):
    def m(self):
    return ["C"]

    class D(B, C):
    pass

    result = D().m()

  56. Question 56 of 60 Method overriding Hard

    What is returned by Sub().call()?

    class Base:
    def call(self):
    return self.step()

    def
    step(self):
    return "base"

    class Sub(Base):
    def __step(self):
    return "sub"

    result = Sub().call()

  57. Question 57 of 60 Method overriding Hard

    What does Sub().f() return?

    class Base:
    def f(self, x=1):
    return f"B{x}"

    class Sub(Base):
    def f(self, x=2):
    return super().f() + f"/S{x}"

  58. Question 58 of 60 Method overriding Hard

    What does constructing Sub() print?

    class Base:
    def init(self):
    self.configure()

    def configure(self):
    print("base")

    class Sub(Base):
    def init(self):
    super().init()
    self.ready = True

    def configure(self):
    print(getattr(self, "ready", "missing"))

    Sub()

  59. Question 59 of 60 Method overriding Hard

    What happens at s.x = 3?

    class Base:
    def init(self):
    self._x = 1

    @property
    def x(self):
    return self._x

    @x.setter
    def x(self, value):
    self._x = value

    class Sub(Base):
    @property
    def x(self):
    return self._x * 10

    s = Sub()
    s.x = 3

  60. Question 60 of 60 Method overriding Hard

    What is the outcome of the final expression?

    from abc import ABC, abstractmethod

    class A(ABC):
    @abstractmethod
    def f(self):
    return "A"

    class B(A):
    def f(self):
    return super().f() + "B"

    result = B().f()

That's unit 4

Answer a few questions and your score shows up here.