Java OCA OCP Practice Question 116

Question

Given:

3. public class Main { 
4.   public enum Days { MON, TUE, WED }; 
5.   public static void main(String[] args) { 
6.     for(Days d : Days.values() ) 
7.       ; 
8.     Days [] d2 = Days.values(); 
9.     System.out.println(d2[2]); 
10.   } 
11. } 

What is the result?

Choose all that apply.

  • A. TUE
  • B. WED
  • C. The output is unpredictable
  • D. Compilation fails due to an error on line 4
  • E. Compilation fails due to an error on line 6
  • F. Compilation fails due to an error on line 8
  • G. Compilation fails due to an error on line 9


B is correct.

Note

Every enum comes with a static values() method that returns an array of the enum's values, in the order in which they are declared in the enum.

A, C, D, E, F, and G are incorrect.




PreviousNext

Related