1Z0-811 Primitives, Strings and Operators Practice Question
Given: double d = 5.0; int i = d; What is the result?
⚠ Common exam trap
Oracle often tests the distinction between implicit and explicit type conversion, and the trap here is that candidates assume Java will automatically truncate the decimal value (like in some other languages), forgetting that Java requires an explicit cast for narrowing conversions.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Compilation fails
In Java, assigning a double to an int without an explicit cast causes a compilation error because double is a 64-bit floating-point type and int is a 32-bit integer type. Java does not allow implicit narrowing conversions due to potential loss of precision, so the code fails to compile.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
5.0
Why it's wrong here
Incorrect.
- ✓
Compilation fails
Why this is correct
Compilation fails because Java does not permit implicit narrowing primitive conversions. Assigning a `double` value to an `int` variable without an explicit cast is a narrowing conversion, as `double` has a larger range and precision than `int`. Java's type system requires an explicit cast, such as `int i = (int) d;`, to acknowledge the potential loss of data or precision during such a conversion.
- ✗
5
Why it's wrong here
Incorrect.
- ✗
Runtime error
Why it's wrong here
Compilation error.
Go deeper
Related to this question
About these practice questions
Courseiva writes every 1Z0-811 question from scratch — 481 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.