Java SE 8 Programmer I — Question 198
Which two code fragments cause compilation errors? (Choose two.)
Answer options
- A. double y1 = 203.22; float fit = y1;
- B. float fit = (float) 1_11.00;
- C. Float fit = 100.00;
- D. int y2 = 100; float fit = (float) y2;
- E. float fit = 100.00F;
Correct answer: A, C
Explanation
Option A causes a compilation error because it attempts to assign a double to a float variable without explicit casting, which is not allowed. Option C is incorrect because 'Float' should be 'float' in Java, leading to a compilation error. The other options are valid and do not produce compilation errors.