Java OCA OCP Practice Question 1640

Question

Which statement about the following program is true?

public enum Main {
  GOOD('C'), BETTER('B'), BEST('A');

  private char v;

  Main(char v) {//from w w w  .  jav a 2 s. co  m
    this.v = v;
  }
  abstract public char getGrade();

  public static void main (String[] args) {
    System.out.println (GOOD.getGrade());     // (1)
  }
}

Select the one correct answer.

  • (a) Since the enum type declares an abstract method, the enum type must be declared as abstract.
  • (b) The method call GOOD.getGrade() in (1) can be written without the enum type name.
  • (c) An enum type cannot declare an abstract method.
  • (d) An enum type can declare an abstract method, but each enum constant must provide an implementation.


(d)

Note

An enum type cannot be declared as abstract.

(b) is not correct, because without the enum type name, it would be a call to an instance method in a static context.

Any abstract method must be implemented by each enum constant.




PreviousNext

Related