Diagnose competing two-parameter overloads

A delivery application's Java test helper returns a code identifying the selected overload. Weight arguments represent grams, and distance arguments represent kilometres. The returned codes are identifiers, not calculated charges.


Java
class RouteProbe {
    static int route(int weightGrams, double distanceKm) {
        return 1;
    }

    static int route(double weightGrams, int distanceKm) {
        return 2;
    }
}


Consider each table call independently inside a method of RouteProbe. Assume these are the only methods named route.


An ambiguous call has applicable overloads but no unique most-specific choice. Enter ambiguous for that outcome, no match when neither overload applies, or the exact returned integer when one overload is selected.

CallOutcome
route(480, 18)
route(480, 18.0)
route(480.0, 18)
route(480.0, 18.0)

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Method Overloading Questions: