Exercise :
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 :
The solution is B.You can write null instanceof integer with no compilation error.
No comments:
Post a Comment