giovedì 28 marzo 2013

Q48


Given:
class Overloading {
       void x(int i) {
             System.out.println("one");
       }

       void x(String s) {
             System.out.println("two");
       }

       void x(double d) {
             System.out.println("three");
       }

       public static void main(String[] args) {
             new Overloading().x(4.0);
       }
}
What is the result?
A.
One
B.
Two
C.
Three
D.
Compilation fails
Risposta C
Visto che si passa un double al costruttore viene usato il costruttore per i double e quindi si ha la stampa di Three .

Nessun commento:

Posta un commento