Solution

ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2016/imperative-programming-resit/5/b/solution

The output is YXWX, without a newline. Apply overload selection followed by dynamic dispatch separately to each call:
  • c.m(a) selects the m(A) signature because the argument's static type is A. The receiver is a D at runtime, so its override prints Y.
  • d.m(b) selects m(B). D.m(B) explicitly calls the inherited implementation with super.m(o), giving X.
  • e.m(a) selects C.m(A), giving W.
  • e.m(b) selects C.m(B), giving X.
Although a actually refers to a B, that runtime type does not select another overload. Dynamic dispatch chooses the implementation of the already selected signature on the receiver.

New to topics? Read the docs here!