Questions: Overload Resolution in Type Systems

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A call f(3, "hello") is made where both f(int, Object) and f(Object, String) are visible and applicable. Which function does the compiler select?

Af(int, Object) — it matches the first argument exactly, which is the tiebreaker
Bf(Object, String) — it matches the second argument exactly, which takes precedence
Cf(int, Object) — it was declared first in the source code
DNeither — the call is ambiguous because no candidate is more specific than the other across all parameters
Question 2 Multiple Choice

In overload resolution, candidate A is considered 'more specific' than candidate B for a given call if:

AA's function body executes in fewer steps than B's at runtime
BEvery argument at the call site requires fewer or no conversions to match A's parameter types compared to B's parameter types
CAll of A's parameter types are supertypes of B's parameter types
DA is declared in the same class as the call site, while B is inherited
Question 3 True / False

If f(int x) and f(Object x) are both defined, calling f(42) will select f(Object x) because Object is the most general type and can accept any argument without error.

TTrue
FFalse
Question 4 True / False

In overload resolution, an 'ambiguous call' compile error means the compiler found no applicable candidates for the given argument types.

TTrue
FFalse
Question 5 Short Answer

Explain why overload resolution can produce an 'ambiguous call' error even when the programmer clearly intended one specific function to be called, and what the compiler is protecting against by refusing to guess.

Think about your answer, then reveal below.