Java OCA OCP Practice Question 99

Question

Which one line in the following code will not compile?

1. byte b = 5; 
2. char c = '5'; 
3. short s = 55; 
4. int i = 555; 
5. float f = 555.5f; 
6. b = s; 
7. i = c; 
8. if (f > b) 
9.   f = i; 
  • A. Line 1
  • B. Line 2
  • C. Line 3
  • D. Line 4
  • E. Line 5
  • F. Line 6
  • G. Line 7
  • H. Line 8
  • I. Line 9


F.

Note

The code b = s will not compile, because converting a short to a byte is a narrowing conversion, which requires an explicit cast.

The other assignments in the code are widening conversions.




PreviousNext

Related