Courseiva
Java Basics and SyntaxhardMultiple ChoiceObjective-mapped

1Z0-811 Java Basics and Syntax Practice Question

Exhibit

public class Test {
    public static void main(String[] args) {
        int a = 5;
        int b = a++ + ++a;
        System.out.println(b);
    }
}

Refer to the exhibit. What is the output?

⚠ Common exam trap

The trap here is that candidates may misread the code and think the loop only sums a subset of elements, or they may incorrectly compute the sum (e.g., forgetting to include the last element) or misapply the subtraction, leading to a wrong answer like 10, 11, or 13.

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

12

The exhibit shows code that initializes an integer array with values 1 through 5. The enhanced for loop iterates over each element, adding each value to the variable 'sum' (starting at 0). After summing all five elements (1+2+3+4+5), sum equals 15. The code then prints the value of sum minus 3, which is 12. Therefore, option C is correct.

Answer analysis

Option-by-option breakdown

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

  • 10

    Why it's wrong here

    Incorrect. a++ uses original value, ++a increments then uses.

  • 13

    Why it's wrong here

    Incorrect. Sum is 12, not 13.

  • 12

    Why this is correct

    Correct. a++ gives 5, ++a gives 7.

  • 11

    Why it's wrong here

    Incorrect. Correct value is 12.

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.