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…
Question
Options
- Asquare...
- Bcircle...
- Csquarecircle...
- DCompilation fails.
How the community answered
(19 responses)- A5% (1)
- C95% (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 > 3is false; theifbranch 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
Community Discussion
No community discussion yet for this question.