Flow Control

Q1: What will be the output of the program?
Float f = new Float('12'); 
switch (f) 
{
    case 12: System.out.println('Twelve'); 
    case 0: System.out.println('Zero'); 
    default: System.out.println('Default'); 
}

A Compilation fails

B Twelve

C Default

D Zero

ANS:A - Zero

The switch statement can only be supported by integers or variables more 'narrow' than an integer i.e. byte, char, short. Here a Float wrapper object is used 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.