Flow Control

Q1: What will be the output of the program?
int x = 3; 
int y = 1; 
if (x = y) /* Line 3 */
{
    System.out.println('x =' + x); 
}

A The code runs with no output.

B x = 1

C Compilation fails.

D x = 3

ANS:A - x = 1

Line 3 uses an assignment as opposed to comparison. Because of this, the if statement receives an integer value instead of a boolean. And so the compilation fails.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.