Multiple choice

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

  1. 1 and 3

  2. 2 and 4

  3. 3 and 5

  4. 4 and 6

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

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 short data types can be used. Short and Long are wrapper classes and reference types can not be used as variables.