ProgrammingModerateInfosys · Wipro NLTH

What is printed?

What is printed?
static void f(int x)    { System.out.print("int"); }
static void f(long x)   { System.out.print("long"); }
static void f(double x) { System.out.print("double"); }
public static void main(String[] a) { byte b = 5; f(b); }
  1. A. int
  2. B. long
  3. C. double
  4. D. Compile error

Correct answer: A. int

A byte widens to int, long or double; the most specific applicable overload, f(int), is chosen.

More OOP with C++ and Java questions

Exams that ask this topic