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.


What does the unary minus operator do in Java?

  1. Negates the operator

  2. Removes minus sign if present

  3. Doubles the value

  4. Converts to positive if negative

The correct answer is: Negates the operator

The unary minus operator in Java is used to negate a value, i.e., changing a positive value to a negative value or vice versa. This means that it performs the opposite operation of the given value. The other options, such as removing a minus sign if present or doubling the value, are not the expected behavior of the unary minus operator. Additionally, while the operator may convert a negative value to a positive value, its main purpose is to simply negate a value. Therefore, the best answer choice is A.