Stages of overload resolution

When the Java compiler meets a call to a method name that has several overloads in a class, it follows a fixed procedure to decide which method the call invokes. Put the following stages of that procedure in the order the compiler carries them out.

  1. 1.

    Search for applicable methods using only exact matches and widening conversions, with no boxing or varargs.

  2. 2.

    Gather every accessible method in the class that has the name used in the call.

  3. 3.

    If still no method applied, search again allowing methods with a varargs parameter.

  4. 4.

    If no method applied, search again allowing boxing and unboxing between primitives and wrapper classes.

  5. 5.

    Among the methods found in the first successful search, choose the most specific one or report an ambiguity error.

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: