Computer Applications

What is the output of the following Java code?

boolean flag = false; 
if (flag) { 
System.out.println("True"); 
} else { 
System.out.println("False"); 
}
  1. True
  2. False
  3. No output
  4. Compilation error

Java

Java Operators

5 Likes

Answer

False

Reason — The code declares a boolean variable flag with the value false, checks it in the if condition, and since it evaluates to false, the if block is skipped and the else block executes, printing False to the output.

Answered By

2 Likes


Related Questions