ExamVeda
Login
Home
This question belongs to Java Program Flow Control
Flow Control
?

Consider the following program written in Java.
class Test{
        public static void main(String args[]){
                int x=7; 
                if(x==2); // Note the semicolon
                System.out.println("NumberSeven");
                System.out.println("NotSeven");
        }
}

What would the output of the program be?

Answer & Solution
Correct Answer: Option A
Let's discuss the solution. Join the discussion
Examveda
Question posted by Examveda
Community

Join the Discussion

2 Comments
Gerry Whizz
Gerry Whizz 5 years ago
if you put a semicolon directly after the condition in an if statement, the java program thinks it's finished with the body of the statement. The indentation of the next line is ignored by Java and it prints everything,,,,,,in this case the output is A
Priyanka Mishra
Priyanka Mishra 9 years ago
How this is possible to write semicolon after if statement ?please help someone.