ExamHoot

Which of the following statements about Java's `Float` wrapper class is correct?

  1. `Float.NaN == Float.NaN` evaluates to `true`

  2. `Float.isNaN(Float.NaN)` returns `true`

  3. `Float.POSITIVE_INFINITY == Float.POSITIVE_INFINITY` is `false`

  4. `Float` cannot be used in arithmetic with `double`

Show answer & explanation

Correct answer

`Float.isNaN(Float.NaN)` returns `true`

Explanation

`Float.NaN` is not equal to any value, including itself, as per IEEE 754. `Float.isNaN()` is the correct way to test for NaN. The `==` operator returns `false` for `Float.NaN == Float.NaN`.

Written by ExamHoot EditorialPublished · Updated

All 10 Java-literals and and wrapper classes questions

  1. 1.Which of the following is a valid octal literal in Java, and when assigned to an `int`, produces the decimal value 63?
  2. 2.Given `Integer a = 100; Integer b = 100; Integer c = 200; Integer d = 200;`, which expression evaluates to `true`?
  3. 3.What is the result of the following operation?
  4. 4.Which of the following statements about Java's `Float` wrapper class is correct?
  5. 5.What is the decimal value of the Java literal `0xFFFF_FFFF` when assigned to an `int`?
  6. 6.Which of the following is a valid Java literal for a `double` and demonstrates the use of scientific notation with an exponent?
  7. 7.Consider the following code:
  8. 8.Which of the following Java literals is NOT a valid way to represent the integer value 256?
  9. 9.Given `Short s = 5;` which of the following expressions is allowed without explicit casting?
  10. 10.What is the output of the following?