Courseiva
Primitives, Strings and OperatorseasyMultiple ChoiceObjective-mapped

1Z0-811 Primitives, Strings and Operators Practice Question

What is the output of: int i = 1; i = i++; System.out.println(i);

⚠ Common exam trap

A common mix-up: candidates assume `i++` always increments the variable before the assignment, leading them to choose 2, but they miss that the post-increment operator returns the original value for the expression, which is then assigned back.

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

1

In Java, the expression `i = i++` uses the post-increment operator, which first stores the current value of `i` (1) for the assignment, then increments `i` to 2, but the stored original value (1) is then assigned back to `i`. Thus, `i` remains 1, and the output is 1.

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 fails

    Why it's wrong here

    Incorrect.

  • 0

    Why it's wrong here

    Incorrect.

  • 2

    Why it's wrong here

    Incorrect.

  • 1

    Why this is correct

    The post-increment operator `i++` first retrieves the current value of `i` (which is 1) for use in the assignment expression. Subsequently, `i` is incremented to 2. However, the assignment `i = ...` then takes the *original* value (1) and assigns it back to `i`, effectively overwriting the incremented value. This specific order of operations, where the assignment occurs *after* the value is retrieved but *before* the incremented value can persist, ensures `i` remains 1 when printed.

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 →

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.