Multiple choice softskills creativity

Output?? boolean var = false; if(var = true) { System.out.println(“TRUE”); } else { System.out.println(“FALSE”); }

  1. Run-time Error

  2. True

  3. Compilation Error

  4. False

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

The code uses assignment (=) instead of equality (). In 'if(var = true)', the assignment happens first (var becomes true), then the condition evaluates the assigned value. Since true is truthy, the if-block executes, printing 'TRUE'. This is a common bug - the programmer likely meant to compare () but accidentally assigned. There's no compilation or runtime error - Java allows boolean assignment in conditions.