1Z0-803 · Question #216
Given the fragment: What is the result?
The correct answer is A. 13480.0. The question asks for the numeric result of an arithmetic expression involving mixed double, int, and float data types.
Question
Given the fragment:
What is the result?
Options
- A13480.0
- B13480.02
- CCompilation fails
- DAn exception is thrown at runtime
How the community answered
(33 responses)- A73% (24)
- B3% (1)
- C9% (3)
- D15% (5)
Why each option
The question asks for the numeric result of an arithmetic expression involving mixed `double`, `int`, and `float` data types.
In Java, when performing arithmetic operations involving `double`, `int`, and `float` types, smaller data types are automatically promoted to the largest type in the expression to prevent data loss. The specific fragment's calculations, applying these promotion rules, would lead to the result `13480.0` as a `double` value.
This result indicates a different calculation or a potential floating-point precision error that is not the intended correct answer for the given fragment.
Mixed-type arithmetic operations are generally handled by Java's automatic type promotion and do not typically cause compilation errors unless there's an explicit type mismatch without promotion.
Standard arithmetic operations with type promotion do not throw runtime exceptions unless specific conditions like division by zero or null pointer access occur, which are not implied by the choice being a numeric result.
Concept tested: Java implicit type promotion in arithmetic
Source: https://docs.oracle.com/javase/specs/jls/se11/html/jls-5.html#jls-5.6.2
Topics
Community Discussion
No community discussion yet for this question.