What, if anything, is wrong with the following code?
public class Main { void test(int x) { switch (x) { case 1://from w ww .jav a 2s . c om case 2: case 0: default: case 4: } } }
Select 1 option
Correct Option is : E
For Option A.
x is an int and int is perfectly valid. long, double, boolean, and float are not valid.
For Option B.
While ordering may be important for the logic being implemented in the code, technically, any order is valid.
For Option C.
This is not necessary.
If there is no break at the end of a case section, the control will fall through to the next case section (even if the case label doesn't match).
For Option D.
Any order of case statements is valid.
E. There is nothing wrong with the code.