QuestionQ12

Object-Oriented Programming

What is the expected result of the following code?

Question Image

  • A it raises an exception
  • B it outputs 2
  • C it outputs 3
  • D it outputs 1
Explanation

Instance method calls use dynamic dispatch: a.doit() invokes Sub_A.make() and returns 1, while b.doit() invokes Sub_B.make() and returns 2. The printed sum is 3.

Community Discussion

No comments yet. Be the first to start the discussion!