Java SE 8 Programmer I — Question 184
Which two code fragments cause a compilation error? (Choose two.)
Answer options
- A. float flt = 100.00F;
- B. float flt = (float) 1_11.00;
- C. Float flt = 100.00;
- D. double y1 = 203.22; float flt = y1;
- E. int y2 = 100; float flt = (float) y2 ;
Correct answer: C, D
Explanation
Option C causes a compilation error because 'Float' is an object wrapper type and cannot be assigned directly like a primitive type. Option D leads to a compilation error as you cannot directly assign a double value to a float variable without an explicit cast. Options A, B, and E are correctly defined and do not cause compilation issues.