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.


For an expression 'a?b:c', what must 'a' be?

  1. An integer

  2. A floating point number

  3. A boolean

  4. Any object

The correct answer is: A boolean

'a' must be a boolean for the ternary operator to work properly. If 'a' is not a boolean, it will be evaluated as a truthy or falsy value and the wrong option (either b or c) will be returned. Option A and B are incorrect because they are data types that are not boolean. Option D is incorrect because any object will also be evaluated as a truthy or falsy value and the wrong option may be returned.