Given:
class Overloading {
int x(double d) {
System.out.println(“one”);
return 0;
}
String x(double d) {
System.out.println(“two”);
return null;
}
double x(double d) {
System.out.println(“three”);
return 0.0;
}
public static void main(String[] args) {
new Overloading().x(4.0)
}
}
What is the result?
A.
One
B.
Two
C.
Three
D.
Compilation fails
Explanation:
overloading of the x method fails as the input argument in all three cases are double. To use overloading of methods the argument types must be different.
Note: The Java programming language supports overloading methods, and Java can distinguish between methods with different method signatures. This means that methods within a class can have the same name if they have different parameter lists
It will throw an Error as Overloadig is not dependent on return type.
D. Compilation fails
C “three”
In this scenario the overloading method is called with a double/float value, 4.0. This
makes the third overload method to run.
Overloaded methods are differentiated by the number and the type of the arguments passed into the method.
My Bad for comment before as “C”.
Answer is : “D”
Explanation :
int x(double d) {.. }
String x(double d) {..}
double x(double d) {..}
This is not Overloading ! and it is not dependent on return Type only.
http://docs.oracle.com/javase/tutorial/java/javaOO/methods.html
The Answer is D.
The time to read or check out the material or web pages we’ve linked to beneath.
By changing the return type it’s not possible to overloading method….so answer will be
Compilation fails.