Multiple choice general knowledge science & technology

Analyze the following code: public class Test { public static void main(String[] args) { System.out.println(max(1, 2)); } public static double max(int num1, double num2) { System.out.println("max(int, double) is invoked"); if (num1 > num2) return num1; else return num2; } public static double max(double num1, int num2) { System.out.println("max(double, int) is invoked"); if (num1 > num2) return num1; else return num2; } }

  1. The program cannot compile because the compiler cannot determine which max method should be invoked

  2. The program cannot compile because you cannot have the print statement in a non-void method

  3. The program runs and prints "max(int, double) is invoked" followed by 2

  4. The program runs and prints "max(double, int) is invoked" followed by 2

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

When max(1, 2) is called with two int arguments, Java's compiler cannot determine whether to invoke max(int, double) or max(double, int) since both require an implicit type conversion (int to double). This ambiguity causes a compilation error.