Here is the code:
public class Test{
public static void main(String [] arguments){ System.out.println(max(1.0, 2)); } public static double max(int num1, double num2){ System.out.println("max(int, double) is invoked"); if(num1 > num 2){ return num1; }else{ return num 2; } public static double max(double num1, int num2){ System.out.println("max(double, int) is invoked"); if(num1 > num 2){ return num1; }else{ return num 2; }
I was confused as to what is going on because I haven't worked with methods other than main.
Here are my answers for this question:
A. The program cannot compile because you cannot have the print statement in a non-void method.
B. The program cannot compile because the compiler cannot determine which max method should be invoked.
C. The program runs and prints "max(int , double)" followed by 2.0
D. The program runs and prints "max(double, int)" followed by 2.0
E. The program runs and prints "max(int, double) is invoked" followed by a 2.0
I don't even understand what is happening in the code, please help because I am eager to learn. This isn't just to get an answer.
EDIT: I am not allowed to use an IDE