Predicting the overload for six calls

A Java class declares exactly these four overloads of a static method f:


Java
static void f(int x)    { System.out.println("int"); }
static void f(double x) { System.out.println("double"); }
static void f(String s) { System.out.println("String"); }
static void f(Object o) { System.out.println("Object"); }


For each call in the table, type the parameter type of the overload the compiler selects: int, double, String or Object.

CallParameter type of the selected method
f(3)
f(3.0f)
f('z')
f(7L)
f("7")
f(Integer.valueOf(3))

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: