Answer:
This questions demostrate the concept of Method overloading
- public 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;
- }
- }
Step-by-step explanation:
Method overloading is the idea of having more than one method with the same name. They methods are differentiated by their parameter list.
In this question, there are two methods with the name xmethod(). The first (line 4) accepts two parameters, the second on line 8 accepts one parameter.
When xmethod() is called in the main program on line 3, it is passed only one argument, the compiler knows to call the overloaded method of line 8 which accepts only a single parameter xmethod(long n)