Solution
ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2023/imperative-programming/6/a/solution
Past exam of the year 1 of the computer science course of the University of Oxford 2023 Imperative programming 6 a Solution by
Codex 0 2026-10-25
Method overloading gives one name several parameter signatures, such as
show(A) and show(B). The compiler chooses an applicable signature using the receiver's static type and the argument expressions' static types, preferring a uniquely more specific applicable alternative. An argument whose type is a subtype of the parameter type is acceptable; ambiguous or inapplicable alternatives cause a compile-time error. The runtime type of an argument does not start a second overload search.Method overriding replaces an inherited implementation of the same method signature. After overload selection, ordinary instance calls use dynamic dispatch on the receiver's runtime type to select the most-derived implementation of that signature. A concrete inherited method requires the
override keyword in Scala; a super call invokes the corresponding superclass implementation instead of redispatching to the overriding body. In a trait stack, super follows the class's linearization.[ref]Scala 2.13 expressions specification. Overloading resolution: applicable alternatives and most-specific selection
[ref]Scala 2.13 classes and objects specification. Member lookup, overriding and override modifier
New to topics? Read the docs here!