mercredi 17 février 2010

Exercice certification SCJP : instanceof

Exercice :

public class Test {

public static void main(String [] args) {

Integer test = new Integer(5);
if (null instanceof Integer) {
System.out.println("null is an integer");
} else if ( test instanceof Integer) {
System.out.println("test is an integer");
} else {
System.out.println("Hello");
}
}

}


What is the result ? (choose one)

A
null is an integer
B test is an integer
C
Hello
D Compilation fails
E An exception is thrown at runtime





Solution :


La solution est B.On peut écrire null instanceof integer sans erreur de compilation

Aucun commentaire:

Enregistrer un commentaire