-
What is the output of this program?
public class bool_operator_Example
{
public static void main(String args[])
{
boolean p = true;
boolean q = !true;
boolean r = p | q;
boolean s = p & q;
boolean z = s ? q : r;
System.out.println(s + " " + z);
}
}
-
- false true
- true false
- true ture
- false false
- None of these
Correct Option: A
Operator | returns true if any one operand is true, thus ‘r = true | false’ is true. Operator & returns p true if both of the operand is true thus s is false. Ternary operator ?: assigns left of ‘:’ if condition is true and right hand of ‘:’ if condition is false. z is false thus z = s ? q : r , assigns r to z , z contains true.
output: false true