Java OCA OCP Practice Question 1644

Question

Given the following program:.

public enum Main {
 GOOD('C')   { public char getGrade() { return v; } },
 BETTER('B') { public char getGrade() { return v; } },
 BEST('A')   { public char getGrade() { return v; } };

 private char v;

 Main(char v) {// ww w  .  ja  v  a  2  s .  co m
   this.v = v;
 }
 // (1) INSERT CODE HERE

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

Which code, when inserted at (1), will make the program print C?.

Select the two correct answers.

  • (a) public char getGrade() { return v; }
  • (b) public int getGrade() { return v; }
  • (c) abstract public int getGrade();
  • (d) abstract public char getGrade();


(a) and (d)

Note

Declarations in (a) and (d) are overridden in each constant-specific class body.

Declarations in (b) and (c) are not overridden by the declarations in the constant-specific class bodies, because of the incompatible return type.




PreviousNext

Related