Courseiva
Control Flow and LoopsmediumMultiple ChoiceObjective-mapped

1Z0-811 Control Flow and Loops Practice Question

A novice developer wrote a condition: if (x = 10) { ... } What is the result?

⚠ Common exam trap

The trap here is that candidates from other programming backgrounds (like C or JavaScript) may expect the assignment to be treated as a truthy value, but Java strictly requires a boolean condition, making this a compilation error.

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 to assign a value, not to compare values. The condition `if (x = 10)` attempts to assign 10 to `x` within an `if` statement, which is not a boolean expression. Java requires the condition in an `if` statement to evaluate to a `boolean`, so this code will not compile. Option D is correct because the compiler will report an error, typically stating 'incompatible types: int cannot be converted to boolean'.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • The condition always evaluates to true

    Why it's wrong here

    This would be true in some languages like C, but not Java.

  • It executes the block if x equals 10

    Why it's wrong here

    Assignment is not comparison; syntax error.

  • Runtime exception thrown

    Why it's wrong here

    No code runs.

  • Compilation error

    Why this is correct

    x=10 is an assignment expression, returning int, which cannot be used as boolean.

About these practice questions

Courseiva writes every 1Z0-811 question from scratch — 481 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or 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.