1Z0-811 Java Basics and Syntax Practice Question
Consider: for(int i=0;i<10;i++) { int x = i; } System.out.println(x); What is the result?
⚠ Common exam trap
The trap here is that candidates often overlook Java's strict block scoping rules and assume a variable declared inside a loop is accessible after the loop, confusing it with languages that have function-level scoping or with the loop variable `i` itself, which is also scoped to the loop block.
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 error
The variable `x` is declared inside the `for` loop block, so its scope is limited to that block. Attempting to use `x` outside the loop (in the `System.out.println(x);` statement) causes a compilation error because `x` is not in scope at that point. The Java compiler enforces block-level scoping rules, and any reference to a variable outside its declared block results in a 'cannot find symbol' error.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
9
Why it's wrong here
Incorrect. x is not accessible outside the loop.
- ✗
10
Why it's wrong here
Incorrect. x is not accessible outside the loop.
- ✓
Compilation error
Why this is correct
Correct. x is out of scope.
- ✗
0
Why it's wrong here
Incorrect. x is not accessible outside the loop.
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.