Java OCA OCP Practice Question 456

Question

Which of the following four constructs are valid?

1. switch (5) /*from  ww w.j a  v  a2  s  .c o  m*/
   { 
      default  : 
   } 

2. switch (5) 
   { 
      default  : break; 
   } 

3. switch (8); 

4. int x = 0; 
      switch (x){ 
   } 

Select 1 option

  • A. 1, 3
  • B. 1, 2, 3
  • C. 3, 4
  • D. 1, 2, 4
  • E. All are valid.


Correct Option is  : D

Note

Code 3 is invalid because a switch statement must have a body.

The body may even be empty as shown in Code 4.




PreviousNext

Related