What line of output is displayed by the following program?
public class Main { static boolean display(boolean b) { System.out.print(" side effect "); return b;/*from ww w .jav a 2 s. co m*/ } public static void main(String[] args) { boolean b1 = true; boolean b2 = false; if (b2 & display(b1)) System.out.println(1); else if (b1 | display(b2)) System.out.println(2); } }
F.
Because we are not using the logical short-circuit operators, the display()
method is invoked in both cases, resulting in " side effect side effect 2" being displayed.