Java OCA OCP Practice Question 1009

Question

What is wrong with the following switch statement?

switch(i == 10) {  
     case '1':  
         ++i;  //ww w . j  a v  a 2  s.c  om
         break;  
     case "2":  
         --i;  
     case 3:  
         i *= 5;  
         break;  
     default  
        i %= 3;  
}  
  • A. The switch expression must evaluate to an integer value.
  • B. The first case specifies a char value.
  • C. The second case specifies a String value.
  • D. There is a break statement missing in the second case.
  • E. An : should follow default.


A, C, and E.

Note

The switch condition must be an integer expression.

The case values must evaluate to integer values during compilation.

A : should follow the default label.




PreviousNext

Related