Multiple choice general knowledge science & technology

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 program prints 'It is even!' because the if condition uses assignment (=) instead of equality comparison (==). The statement 'even = true' assigns true to the variable even and returns true as the expression result, so the if block executes. This is a common mistake - using assignment instead of comparison. There is no syntax or runtime error, and output is produced.