Java OCA OCP Practice Question 429

Question

Given the following:

public enum Paint { 
     BROWN, BLUE, YELLOW; 
} 

Which of the following are legal?

A.  enum PatternedPaint extends Paint { 
          STRIPES, DOTS, PLAIN; /*  w  w w  .  j a  va  2s  . c o  m*/
         } 

B. Paint wp = Paint.BLUE; 

C. Paint wp = new Paint(Paint.BLUE); 

D. void aMethod(Paint wp) {  
             System.out.println(wp); 
         } 

E.  int hcode = Paint.BLUE.hashCode(); 


B, D, E.

Note

A and C are illegal because an enum may not be extended or instantiated.

B is a legal use of one of the enum's constants.

D legally passes an enum into a method.

E legally calls a method that all enums inherit from Object.




PreviousNext

Related