Question 1
What is the output of the following program? ```java public class Main { public static void main(String[] args) { int x = 0; boolean r = (x++ > 0) | (x++ > 0); System.out.println(x + " " + r); } } ```
A. 2 trueCorrect answer
Single | never short-circuits, so both operands run: 0 > 0 false (x→1) then 1 > 0 true (x→2), and false | true is true (JLS 7 §15.22.2).
B. 1 false
This treats | as if it short-circuited like ||, but single | always evaluates both operands, so x reaches 2 and the true right operand makes the result true.
C. 2 false
The count of 2 is right, but the boolean is wrong: the right operand 1 > 0 is true, so false | true evaluates to true.
D. 1 true
This assumes only one increment runs, but | never short-circuits, so both x++ operands execute and x ends at 2, not 1.
Explanation
Single | is the NON-short-circuit OR: both operands are always evaluated. Left: 0 > 0 false (x→1). Right: 1 > 0 true (x→2). false | true is true. Contrast with ||, which would also have evaluated both here (left was false) — the visible difference between | and || only appears when the left side is true.