Search code examples
javabooleanconditional-operatorunary-operator

Java -Boolean expression of variable and it's inverse


This is quite confusing.
Question: Give the value of each of these expressions.

x && !x

Would this be true or false?


Solution

  • true && !true => false
    false && !false => false
    

    the only other option is

    Boolean x = null;
    x && !x => NullPointerException.