A

Admin • 828.70K Points
Coach

Q. What is the output of this program?

Code:
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);
}
}
  • (A) false true
  • (B) true false
  • (C) true true
  • (D) false false
  • Correct Answer - Option(A)
  • Views: 14
  • Filed under category Java
  • Hashtags:

Explanation by: Admin
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

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.