Q2
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
|
Il risultato è che la classe non compila. Un metodo è univoco per nome + firma e quelli qui presenti sono uguali sia nel nome che nella firma, quindi sono duplicati.
Riferimenti:
Overload
Nessun commento:
Posta un commento