1Z0-811 Java Basics and Syntax Practice Question
Which assignment requires an explicit cast to compile?
⚠ Common exam trap
Oracle often tests the misconception that any numeric literal with a suffix (like `L` or `f`) automatically requires a cast, but the trap here is that only narrowing conversions (e.g., `long` to `int`) need explicit casting, not widening ones or assignments of the same 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
✓
int i = 10L;
Requires an explicit cast because it assigns a `long` literal (10L) to an `int` variable. In Java, `long` is a 64-bit type and `int` is 32-bit, so this is a narrowing primitive conversion that loses precision and must be explicitly cast with `(int)`. Without the cast, the compiler rejects it as a possible lossy conversion.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
int i = 10L;
Why this is correct
Correct. long to int needs explicit cast.
- ✗
double d = 10;
Why it's wrong here
Incorrect. int to double is widening, no cast needed.
- ✗
long l = 10;
Why it's wrong here
Incorrect. int to long is widening, no cast needed.
- ✗
float f = 10.5f;
Why it's wrong here
Incorrect. float literal, no cast needed.
Go deeper
Related to this question
About these practice questions
This 1Z0-811 question is part of Courseiva's 481-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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.