Courseiva
Primitives, Strings and OperatorshardMultiple ChoiceObjective-mapped

1Z0-811 Primitives, Strings and Operators Practice Question

Exhibit

int a = 10;
int b = 5;
int c = a++ + --b * 2;
System.out.println(c);

Refer to the exhibit. Given the code, what is the value printed to the console?

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

18

18 (option C). The expression `a++ + --b * 2` is evaluated according to Java operator precedence: postfix increment (`a++`) uses the current value of `a` (10) then increments `a` to 11; prefix decrement (`--b`) decrements `b` from 5 to 4 then uses 4; multiplication has higher precedence than addition, so `--b * 2` computes 4 * 2 = 8; then addition: 10 + 8 = 18. Option A (19) would result if the postfix increment had been applied before the rest of the expression (i.e., using 11 instead of 10). Option B (21) would result if both increments were applied before evaluation (a becomes 11, b becomes 4, and then 11 + 4 * 2 = 11 + 8 = 19, not 21; actually 21 is far off). Option D (20) would result if addition were performed before multiplication (10 + 4 = 14, then 14 * 2 = 28, not 20; 20 is not directly derivable). Thus only step-by-step evaluation yields 18.

Answer analysis

Option-by-option breakdown

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

  • 19

    Why it's wrong here

    Incorrect: Possible if post-increment was applied after entire expression.

  • 21

    Why it's wrong here

    Incorrect: Would result if both a and b incremented before calculation.

  • 18

    Why this is correct

    The value 18 is printed because Java's operator precedence rules are correctly applied to the arithmetic expression. Multiplication operations are performed before addition. Therefore, if the code involved an expression like `5 + 2 * 6 + 1`, `2 * 6` would evaluate to `12` first. Subsequently, the additions `5 + 12 + 1` are executed from left to right, resulting in `17 + 1`, which yields the final value of 18. This satisfies the constraint of correctly evaluating expressions based on operator hierarchy.

  • 20

    Why it's wrong here

    Incorrect: Would result if multiplication was ignored or precedence reversed.

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.