Multiple choice technology programming languages

Given: class Hexy { public static void main(String[] args) { Integer i = 42; String s = (i<40)?"life":(i>50)?"universe":"everything"; System.out.println(s); } } What is the result?

  1. null

  2. life

  3. universe

  4. everything

  5. Compilation fails

  6. An exception is thrown at runtime

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The nested ternary first checks i<40 (false), then i>50 (false), so the final else clause is chosen. Hence s is assigned "everything". All other options are incorrect because the conditions do not match the value 42.