Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Analyze the following code: public class Test { public static void main(String[]

ID: 3565487 • Letter: A

Question

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.

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.

Explanation / Answer

D.The program displays int, long followed by 5. is printed on the console

Since you are calling xMethod(5, 500L)

where 5 is integer and 500L is long

compiler looks for method with arguments (int ,long)

and founds  int xMethod(int n, long l)

and prints int,long on console fynally this method returns n where n is 5 in our case