Java OCA OCP Practice Question 2603

Question

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

public class Swimmer { 
   enum Letter { 
      A, B { //from  w  ww  .  ja  v  a2s .c  o m
         public boolean hasFins() { return true; }}, 
      C, D, E, F; 
      public abstract boolean hasFins(); 
   } 
   public static void main(String[] args) { 
      System.out.println(Letter.B); 
      System.out.println(Letter.B.ordinal()); 
      System.out.println(Letter.B.hasFins()); 
      System.out.println(Letter.C.hasFins()); 
   } 
} 
  • A. fish
  • B. B
  • C. 0
  • D. 1
  • E. false
  • F. true
  • G. The code does not compile.


G.

Note

This question appears to be about enums but is really about abstract methods.

Just as an abstract superclass requires concrete subclasses to have an implementation, abstract enum methods require each enum type to implement the method.




PreviousNext

Related