Courseiva
Java Basics and SyntaxmediumMultiple ChoiceObjective-mapped

1Z0-811 Java Basics and Syntax Practice Question

A developer writes: if (x = 5) { System.out.println("x is 5"); } What is the result?

⚠ Common exam trap

Oracle often tests the distinction between assignment (`=`) and comparison (`==`) in conditional statements, exploiting the common misconception that Java behaves like C/C++ where an assignment expression can be used as a boolean condition.

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

In Java, the assignment operator `=` is used for assignment, not comparison. The expression `x = 5` assigns the value 5 to variable `x` and returns the assigned value (5). Since the condition in an `if` statement must be a boolean expression, and `int` cannot be implicitly converted to `boolean`, the compiler throws a compilation error. This is a fundamental syntax rule in Java, unlike in C/C++ where such an assignment would be allowed as a truthy check.

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

    Why this is correct

    Assignment is not boolean and cannot be used in if condition.

  • Prints "x is 5" if x equals 5

    Why it's wrong here

    Code does not compile.

  • No output

    Why it's wrong here

    Code does not compile.

  • Prints "x is 5" always

    Why it's wrong here

    Code does not compile.

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 →

How Courseiva writes practice questions · Editorial policy

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.