Which statements about the output of the following programs are true?
public class Main{ public static void main (String args [] ){ int i = 0 ; boolean bool1 = true; boolean bool2 = false; boolean bool = false; bool = (bool2 & method1 ("1")); //1 bool = (bool2 && method1 ("2")); //2 bool = (bool1 | method1 ("3")); //3 bool = (bool1 || method1 ("4")); //4 } //from w w w .j av a 2s.c o m public static boolean method1 (String str){ System .out.println (str); return true; } }
Select 2 options
Correct Options are : A C
& and | do not short circuit the expression.
The value of all the expressions (1 through 4) can be determined by looking at the first part.
&& and || do not evaluate the rest of the expression if the result of the whole expression can be known by evaluating the left operand, so method1 () is not called for 2 and 4.