What is the result?

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?

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



Leave a Reply 2

Your email address will not be published. Required fields are marked *


Daniel Reis

Daniel Reis

Question 13 is equal

Noname

Noname

Compilation fails. We are not allowed to have more than one method with similar signature (the signature doesn’t include method’s return type)