Short-Circuit Logic Trace
A boolean method with a print side-effect is evaluated inside a compound logical expression to observe short-circuiting behavior.
What is printed when the following Java program is compiled and run?
public class QuestionTrace {
public static boolean check(int n) {
System.out.print(n);
return n > 5;
}
public static void main(String[] args) {
if (check(3) && check(6)) {
System.out.print("A");
} else {
System.out.print("B");
}
}
}
A
36B
B
3B
C
36A
D
3A
Question Leaderboard
Not enough data yet to show leaderboard.
