230k views
4 votes
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; } }

1 Answer

1 vote

Answer:

This code will give Error.

Step-by-step explanation:

This code will give error because we have passed the argument 5 as double by using typecasting.We have two methods named xMethod but with arguments as int and long none of them has argument as double.The compiler will not be able to find the method with double argument.So this code will not run because of this reason.

User Jamapag
by
5.6k points