Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Mastering Java: The Ultimate Quiz for 'Thinking in Java'. Dive deep into Java with multiple-choice questions. Challenge yourself with quiz questions designed to test and improve your understanding of the 'Thinking in Java' book. Get ready for your exam!

Practice this question and more.


Which of these logical operators is used to perform a logical 'exclusive or'?

  1. !

  2. &&

  3. ||

  4. ^

The correct answer is: ^

The logical 'exclusive or' operator, also known as XOR, returns true only if one of the operands is true and the other is false. This type of operation is not possible with a single logical operator. Option A (!) is the logical 'not' operator, which reverses the value of a boolean expression. Options B (&&) and C (||) are the logical 'and' and 'or' operators respectively, which both return true if both operands are true. Therefore, option D (^) is the only suitable choice for performing a 'logical exclusive or' operation.