Flow Control

Q1:
public void test(int x) 
{ 
    int odd = 1; 
    if(odd) /* Line 4 */
    {
        System.out.println('odd'); 
    } 
    else 
    {
        System.out.println('even'); 
    } 
}
Which statement is true?

A Compilation fails.

B "even" will always be output.

C "odd" will always be output.

D "odd" will be output for odd values of x, and "even" for even values.

ANS:A - Compilation fails.

The compiler will complain because of incompatible types (line 4), the if expects a boolean but it gets an integer.



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.