Flow Control

Q1: What will be the output of the program?
int i = 1, j = -1; 
switch (i) 
{
    case 0, 1: j = 1; /* Line 4 */
    case 2: j = 2; 
    default: j = 0; 
} 
System.out.println('j = ' + j); 

A j = -1

B j = 0

C j = 1

D Compilation fails.

ANS:A - j = -1

The case statement takes only a single argument. The case statement on line 4 is given two arguments so the compiler complains.



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.