To answer this question, let's go through each option to understand why it is correct or incorrect:
Option A) int Long - This option is correct.
In the given code, the go()
method is overloaded with three different parameter types: Long
, Short
, and int
.
On line 19, the go(y)
statement passes a short
variable y
as an argument to the go()
method. Since there is no method that exactly matches the parameter type short
, the compiler looks for the closest matching method. In this case, it finds the go(int n)
method, which can accept a short
argument due to implicit narrowing conversion. Therefore, "int " is printed.
On line 20, the go(z)
statement passes a long
variable z
as an argument to the go()
method. Since there is an exact match with the parameter type Long
, the go(Long n)
method is called and "Long " is printed.
Therefore, the output will be "int Long".
Option B) Short Long - This option is incorrect because the go(Short n)
method is not called in the given code.
Option C) Compilation fails - This option is incorrect because there are no compilation errors in the given code.
Option D) An Exception thrown at runtime - This option is incorrect because there are no exceptions thrown in the given code.
The correct answer is option A.