Analyze the following code: public class Test {public static void main(String[] args) {System.out.println(xMethod(5, 500L));} public static int xMethod(int n, long l) {System.out.println("int, long");return n;} public static long xMethod(long n, long l) {System.out.println("long, long");return n;} }
A. The program does not compile because the compiler cannot distinguish which xmethod to invoke.
B. The program runs fine but displays things other than 5.
C. The program displays long, long followed by 5.
D. The program displays int, long followed by 5.
查看答案
Analyze the following code: class Test {public static void main(String[] args) {System.out.println(xmethod(5));} public static int xmethod(int n, long t) {System.out.println("int");return n;} public static long xmethod(long n) {System.out.println("long");return n;} }
A. The program displays long followed by 5.
B. The program displays int followed by 5.
C. The program does not compile because the compiler cannot distinguish which xmethod to invoke.
D. The program runs fine but displays things other than 5.
Analyze the following code. public class Test {public static void main(String[] args){System.out.println(m(2));} public static int m(int num) {return num;}public static void m(int num) {System.out.println(num);} }
A. The program runs and prints 2 twice.
B. The program has a compile error because the two methods m have the same signature.
C. The program runs and prints 2 once.
D. The program has a compile error because the second m method is defined, but not invoked in the main methoD.
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;elsereturn num2;} public static double max(double num1, int num2) {System.out.println("max(double, int) is invoked"); if (num1 > num2)return num1;elsereturn num2;} }
A. The program runs and prints 2 followed by "max(int, double)" is invoked.
B. The program runs and prints 2 followed by "max(double, int)" is invoked.
C. The program cannot compile because you cannot have the print statement in a non-void method.
D. The program cannot compile because the compiler cannot determine which max method should be invoked.
Analyze the following code: class Test { public static void main(String[] args) {System.out.println(xMethod((double)5));} public static int xMethod(int n) {System.out.println("int");return n;} public static long xMethod(long n) {System.out.println("long");return n;} }
A. The program displays int followed by 5.
B. The program displays long followed by 5.
C. The program runs fine but displays things other than 5.
D. The program does not compile.