Home » JAVA Programming » Basic Operators » Question
  1. 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);
    }
    }
    1. false true
    2. true false
    3. true ture
    4. false false
    5. 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



Your comments will be displayed only after manual approval.