1Z0-811 Java Basics and Syntax Practice Question
A developer writes the following code: int x = 5; int y = x++; What are the values of x and y after execution?
⚠ Common exam trap
It's easy for candidates to confuse post-increment (`x++`) with pre-increment (`++x`), mistakenly thinking the incremented value is assigned to `y`.
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
✓
x = 6, y = 5
The post-increment operator `x++` returns the original value of `x` (5) before incrementing. Therefore, `y` is assigned 5, and `x` becomes 6 after the increment. This is a fundamental behavior of post-increment in Java.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
x = 5, y = 5
Why it's wrong here
Incorrect; x becomes 6 after increment.
- ✗
x = 5, y = 6
Why it's wrong here
Incorrect; y gets the original value.
- ✓
x = 6, y = 5
Why this is correct
Correct: y=5 (original x), then x increments to 6.
- ✗
x = 6, y = 6
Why it's wrong here
Incorrect; y gets the pre-increment value.
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.