Multiple choice

public void test(int x) { int odd = 1; if(odd) /* Line 4 */ { System.out.println(odd); } else { System.out.println(even); } }

Which statement is true?

  1. compilation fails.

  2. odd will always be output.

  3. even will always be output.

  4. odd will be output for odd values of x, and even for even values.

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

The compiler will complain because of incompatible types (line 4), the if expects a boolean but it gets an integer.