Flow Control

Q1:
switch(x) 
{ 
    default:  
        System.out.println('Hello'); 
}
Which two are acceptable types for x?
  1. byte
  2. long
  3. char
  4. float
  5. Short
  6. Long

A 4 and 6

B 3 and 5

C 2 and 4

D 1 and 3

ANS:A - 1 and 3

Switch statements are based on integer expressions and since both bytes and chars can implicitly be widened to an integer, these can also be used. Also shorts can be used. Short and Long are wrapper classes and reference types can not be used as variables.



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.