Multiple choice technology programming languages

Analyze the following code: boolean even = false; if (even = true) { System.out.println("It is even!"); }

  1. The program has a syntax error.

  2. The program has a runtime error.

  3. The program runs fine, but displays nothing.

  4. The program runs fine and displays It is even!.

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

The expression even = true is an assignment operator, not a comparison operator (==). It assigns true to even and evaluates to true, causing the if statement block to execute and print It is even!.