Courseiva
Controlling Program FloweasyMultiple ChoiceObjective-mapped

1Z0-829 Controlling Program Flow Practice Question

What is the output of the following code snippet? int x = 5; if(x > 0) { System.out.print('A'); } else if(x > 2) { System.out.print('B'); } else { System.out.print('C'); }

⚠ Common exam trap

The trap here is that candidates mistakenly think the `else if` condition is also evaluated or that multiple branches can execute, confusing the if-else-if chain with a series of independent if statements.

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

A

The condition `x > 0` evaluates to true (x = 5), so the code prints 'A' and then exits the entire if-else-if chain. The subsequent `else if` and `else` blocks are skipped entirely, so only 'A' is output.

Answer analysis

Option-by-option breakdown

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

  • AB

    Why it's wrong here

    Only one branch executes.

  • C

    Why it's wrong here

    The else branch is not reached because a prior condition was true.

  • B

    Why it's wrong here

    The else-if branch is not reached because the first condition was true.

  • A

    Why this is correct

    x > 0 is true, so the first branch executes and prints 'A'.

About these practice questions

One of 513 original 1Z0-829 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

Same concept, more angles

1 more way this is tested on 1Z0-829

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. Given the code snippet: int x = 10; if (x > 5) { System.out.print("A"); } else if (x > 7) { System.out.print("B"); } else { System.out.print("C"); } What is the output?

easy
  • A.C
  • B.ABC
  • C.A
  • D.B

Why C: The if-else chain evaluates conditions sequentially. Since x=10 satisfies x > 5, the first block executes and prints 'A'. The else if and else branches are skipped entirely because the first condition was true. Thus, only 'A' is output.

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 1Z0-829 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-829 exam.