nerdexam
Oracle

1Z0-808 · Question #75

Given the code fragment: int b = 3; if ( (b > 3) ) { System.out.println("square"); } else { System.out.println("circle"); } System.out.println("..."); What is the result?

The correct answer is C. squarecircle. The marked answer (C) is actually incorrect - the correct answer is B: circle... Here's the breakdown: b is assigned 3, so the condition b > 3 evaluates to false (3 is not greater than 3). This means the else branch executes, printing "circle". The final…

Using Operators and Decision Constructs

Question

Given the code fragment: int b = 3; if ( (b > 3) ) { System.out.println("square"); } else { System.out.println("circle"); } System.out.println("..."); What is the result?

Options

  • Asquare...
  • Bcircle...
  • Csquarecircle...
  • DCompilation fails.

How the community answered

(19 responses)
  • A
    5% (1)
  • C
    95% (18)

Explanation

The marked answer (C) is actually incorrect - the correct answer is B: circle...

Here's the breakdown:

b is assigned 3, so the condition b > 3 evaluates to false (3 is not greater than 3). This means the else branch executes, printing "circle". The final System.out.println("...") is outside the if-else block entirely, so it always runs, appending "..." to the output.

Why each option is wrong:

  • A (square...) - Wrong because b > 3 is false; the if branch never executes.
  • C (squarecircle...) - Impossible; an if-else guarantees exactly one branch runs, never both.
  • D (Compilation fails) - The code is syntactically valid; extra parentheses around a condition are legal in Java.

Memory tip: In an if-else, think of it as a fork in the road - you always take exactly one path. Any println after the closing brace of the entire if-else block runs unconditionally, regardless of which branch was taken.

Topics

#if-else statements#boolean expressions#conditional logic#control flow

Community Discussion

No community discussion yet for this question.

Full 1Z0-808 Practice