1Z0-811 Java Basics and Syntax Practice Question
Exhibit
Refer to the exhibit.
public class Test {
public static void main(String[] args) {
int x = 10;
if (x = 5) {
System.out.println("Equal");
}
}
}The code does not compile. What is the error?
⚠ Common exam trap
Oracle often tests the distinction between assignment (`=`) and comparison (`==`) in conditional statements, exploiting the fact that beginners mistakenly think assignment is valid in an `if` condition because it works in other languages like C or JavaScript.
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
✓
Assignment instead of comparison in if condition
The code uses a single equals sign `=` (assignment) inside the `if` condition instead of `==` (comparison). In Java, `if (x = 5)` assigns the value 5 to `x` and then evaluates the assignment expression to the assigned value (5), which is an `int`, not a `boolean`. The `if` statement requires a `boolean` expression, so this causes a compilation 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.
- ✗
Missing semicolon after if condition
Why it's wrong here
Semicolon is not needed there.
- ✗
Variable x is not initialized
Why it's wrong here
x is initialized to 10.
- ✗
System.out.println syntax error
Why it's wrong here
Syntax is correct.
- ✓
Assignment instead of comparison in if condition
Why this is correct
Correct: x = 5 is assignment, not boolean.
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.