Java OCA OCP Practice Question 2871

Question

Given:

1. enum Letter {A, B, C};  
2. public class Main {  
3.   public static void main(String[] args) {  
4.     Main p = new Main();  
5.     Letter[] v = Letter.values();  /*from  ww w.j  av  a  2 s.c o m*/
6.     v = Letter.getValues();  
7.     for(Letter me: Letter.values())   p.getEnum(me);  
8.     for(int x = 0; x < Letter.values().length; x++)   p.getEnum(v[x]);  
9.     for(int x = 0; x < Letter.length; x++)   p.getEnum(v[x]);  
10.     for(Letter me: v)   p.getEnum(me);  
11.   }    
12.   public void getEnum(Letter e) {  
13.     System.out.print(e + " ");  
14. } } 

Which line(s) of code will cause a compiler error? (Choose all that apply.)

  • A. line 1
  • B. line 5
  • C. line 6
  • D. line 7
  • E. line 8
  • F. line 9
  • G. line 10
  • H. line 12


C and F are correct.

Note

At line 6, compilation will fail because the method getValues() is not defined.

At line 9, the compilation will fail because enums don't have a length attribute.

There are no compilation problems with the code described on these lines, although line 7 is probably most common because it doesn't need line 5.




PreviousNext

Related