Java OCA OCP Practice Question 2940

Question

What is the result of the following code snippet? (Choose all that apply.)

3:  final int movieRating = 4; 
4:  int select = 9; 
5:  switch(select) { 
6:     case 0: /*from  w w w .j a  va2  s.c om*/
7:     case select: System.out.println("Awful"); break; 
8:     case movieRating:  System.out.println("Great"); break; 
9:     case 4: 
10:    default: 
11:    case (int)'a': 
12:    case 1*1: System.out.println("Too be determined"); break; 
13: } 
  • A. The code will not compile because of line 6.
  • B. The code will not compile because of line 7.
  • C. The code will not compile because of line 9.
  • D. The code will not compile because of line 11.
  • E. The code will not compile because of line 12.


B,C.

Note

The code will not compile due to problems with the case values.

First, select is not a constant value; therefore line 6 will not compile.

If it was marked final, it would compile, so B is correct.

Next, Line 9 has the same case value of 4 as Line 8.

Since there's no option to remove Line 8 available in the choices, Line 9 should be removed and C is correct.

The other answers are incorrect, because the rest of the lines of the code compile.




PreviousNext

Related