1Z0-811 Primitives, Strings and Operators Practice Question
A method has parameters: int x, double y. It performs x += y; and returns x. What is the range behavior?
⚠ Common exam trap
The trap here is that candidates mistakenly believe the result is promoted to double (option D) because they focus on the binary numeric promotion during the addition, forgetting that the compound assignment operator includes an implicit narrowing cast back to the left-hand variable's type.
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
✓
Result is truncated to int.
When the compound assignment operator += is used with an int and a double, the right-hand operand (double) is implicitly narrowed to int via a primitive narrowing conversion. This truncates the fractional part of the double value, and the result is stored as an int. The operation compiles without error and does not throw a runtime exception.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Compilation error: cannot apply += between int and double.
Why it's wrong here
Compound assignment compiles.
- ✗
Lossy conversion causes runtime exception.
Why it's wrong here
No exception; value is truncated.
- ✓
Result is truncated to int.
Why this is correct
Implicit narrowing cast.
- ✗
x is promoted to double, result is double.
Why it's wrong here
x remains int due to cast.
Go deeper
Related to this question
About these practice questions
One of 481 original 1Z0-811 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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.