Exercise :
Given the following :
public class Test {
public static void main(String [] args) {
int num = 1;
if ( num == 'a') {
System.out.println("Good result !");
} else {
System.out.println("Result:" + num);
}
}
}
What is the result ? (choose one)
A Good result !
B Result:1
C Compilation fails
D An exception is thrown at runtime
Solution :
The result is C.There is no compilation error.You can compare 1 with 'a' because the comparison use the unicode value of a.So it's correct to compare 1 with 'a'.
No comments:
Post a Comment