Java OCA OCP Practice Question 177

Question

Given:

class Main { 
  public static void main(String[] args) { 
    int i = 42; 
    String s = (i<40)?"life":(i>50)?"universe":"everything"; 
    System.out.println(s); 
  } 
} 

What is the result?

  • A. null
  • B. life
  • C. universe
  • D. everything
  • E. Compilation fails
  • F. An exception is thrown at runtime


D is correct.

Note

This is a ternary nested in a ternary.

Both of the ternary expressions are false.




PreviousNext

Related