Courseiva
Java Basics and SyntaxmediumMultiple ChoiceObjective-mapped

1Z0-811 Java Basics and Syntax Practice Question

Exhibit

Refer to the exhibit.
public class Test {
    public static void main(String[] args) {
        int a = 10;
        int b = 20;
        System.out.println(a + b);
        System.out.println("Sum: " + a + b);
    }
}

What is the output of this program?

⚠ Common exam trap

This question tests the behavior of a while loop with a condition that is not correctly controlling the number of iterations (the loop runs only once due to a separate variable 'x' that is not updated in the loop body), and the difference between arithmetic addition and string concatenation when using the '+' operator with mixed types.

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

30 Sum: 1020

The code compiles and runs without error. The first line prints 30 because the loop variable 'i' ends up as 30 due to a bug in the loop logic. The second line prints 'Sum: 1020' because the variable 'sum' holds the value 10 (the loop only sums certain values incorrectly), and the expression 'Sum: ' + sum + '20' concatenates the string 'Sum: ', the integer 10, and the string '20' to produce 'Sum: 1020'. 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.

  • Runtime exception

    Why it's wrong here

    No exception.

  • Compilation error

    Why it's wrong here

    No error.

  • 30 Sum: 1020

    Why this is correct

    This output correctly reflects a program that first prints an initial value, likely a variable assigned `30`, followed by a separate calculation and print statement. The "Sum: 1020" indicates a summation operation, where the loop's iteration range or conditional logic precisely excludes a specific value from the total. For instance, if the program calculates the sum of integers from 1 to 45 (which is 1035) but explicitly omits the value 15 from the sum, the resulting total would be 1020, satisfying the exact output required.

  • 30 Sum: 30

    Why it's wrong here

    The second line would be Sum: 1020.

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.