Java OCA OCP Practice Question 1538

Question

What is the result of executing the following code when the value of i is 5:

switch  (i){//from  ww  w.  j a v a  2s .  c o  m
    default:
    case 1:
        System.out.println (1);
    case 0:
        System.out.println (0);
    case 2:
        System.out.println (2);
        break;
    case 3:
        System.out.println (3);
}

Select 1 option

  • A. It will print 1 0 2
  • B. It will print 1 0 2 3
  • C. It will print 1 0
  • D. It will print 1
  • E. Nothing will be printed.


Correct Option is  : A

Note

The type of the Expression must be char, byte, short, or int or a compile-time error occurs.

Java 7 allows String as well.

The class of the switch variable may also be a Wrapper class:Character, Byte, Short, or Integer.




PreviousNext

Related