Java OCA OCP Practice Question 2754

Question

Given:

42.  String s = "";  
43.  if(011 == 9) s += 4;  
44.  if(0x11 == 17) s += 5;  
45.  Integer I = 12345;  
46.  if(I.intValue() == Integer.valueOf("12345")) s += 6;  
47.  System.out.println(s); 

What is the result?

A.   5
B.   45
C.   46
D.   56
E.   456
F.   Compilation fails.
G.   An exception is thrown at runtime.


E is correct.

Note

Line 43 is comparing an octal int to an int.

Line 44 is comparing a hexadecimal int to an int.

Line 46 is comparing an int to an Integer, which is unboxed before the comparison is made.




PreviousNext

Related