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.


How does the 'Conversion' example output 'true' for variable 'z' when using the 'b' conversion?

  1. Because 'z' is non-null and not boolean type

  2. Because 'z' is a boolean with true value

  3. Because 'z' is a null reference

  4. Because 'z' has a numeric value of zero

The correct answer is: Because 'z' is a boolean with true value

The reason why the other choices are incorrect is because A: Since the 'b' conversion only looks at the existence of a value and not the data type, the boolean type of 'z' is irrelevant. C: Since 'z' is assigned a value of 'true' and not null, it cannot be a null reference. D: The numeric value of 'z' is not used in this conversion, only the boolean value. Therefore, 'z' can have any numeric value and still output 'true'.