Examveda
Examveda

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?

A. NumberSeven NotSeven

B. NumberSeven

C. NotSeven

D. Error

E. 7

Answer: Option A


This Question Belongs to Java Program >> Flow Control

Join The Discussion

Comments ( 2 )

  1. Gerry Whizz
    Gerry Whizz :
    2 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

  2. Priyanka Mishra
    Priyanka Mishra :
    6 years ago

    How this is possible to write semicolon after if statement ?please help someone.

Related Questions on Flow Control