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.
題解
程式第8行和第13行,x方法的簽名(Signature)都是相同的,因此會發生編譯錯誤。