1Z0-808 · Question #14
Given the code fragment: 3. public static void main(String[] args) { 4. int iVar = 100; 5. float fVar = 100.100f; 6. double dVar = 123; 7. iVar = fVar; 8. fVar = iVar; 9. dVar = fVar; 10. fVar =…
The correct answer is A. Line 7 D. Line 10 F. Line 12. Lines 7, 10, and 12 all attempt narrowing conversions without an explicit cast - assigning a larger/wider type into a smaller/narrower one, which Java refuses to compile automatically. Line 7 (iVar = fVar) assigns a float into an int; line 10 (fVar = dVar) assigns a double into…
Question
Options
- ALine 7
- BLine 8
- CLine 9
- DLine 10
- ELine 11
- FLine 12
How the community answered
(41 responses)- A88% (36)
- B2% (1)
- C7% (3)
- E2% (1)
Explanation
Lines 7, 10, and 12 all attempt narrowing conversions without an explicit cast - assigning a larger/wider type into a smaller/narrower one, which Java refuses to compile automatically. Line 7 (iVar = fVar) assigns a float into an int; line 10 (fVar = dVar) assigns a double into a float; and line 12 (iVar = dVar) assigns a double into an int - all three lose precision or magnitude, so the compiler demands an explicit cast like (int).
The distractors (B, C, E) are all widening conversions, which Java performs implicitly with no cast required: line 8 (fVar = iVar) widens int → float, line 9 (dVar = fVar) widens float → double, and line 11 (iVar = iVar) is a same-type assignment - all perfectly legal.
Memory tip: Think of the type hierarchy as a one-way escalator: int → long → float → double. Going up (widening) is free; going down (narrowing) requires a cast token - if you forget the cast, the compiler stops you cold.
Topics
Community Discussion
No community discussion yet for this question.