QuestionQ47

Working with Selected Classes from the Java API

Given:

Question Image

And the following commands:

Question Image

What is the result?

  • A 1 null
  • B true false
  • C false false
  • D true true
  • E A ClassCastException is thrown at runtime.
Explanation

Both Boolean.valueOf(String) and Boolean(String) produce true only when the input string equals "true" without regard to case. Neither "1" nor "null" meets that condition, so both Boolean values are false.

Community Discussion

No comments yet. Be the first to start the discussion!