Java OCA OCP Practice Question 1654

Question

What will be the result of compiling and running the following code?.

enum Rank {/*from   w ww  . j  a va 2 s  . com*/
  FIRST(20), SECOND(0), THIRD(8);
  Rank(int value) {
    System.out.print(value);
  }
}
public class Main {
  public static void main (String[] args) {
    System.out.println("\n" + Rank.values().length);
  }
}

Select the one correct answer.


(a)  The program will compile and print:

     3/*from   w  w  w  .  ja v  a 2 s. c om*/

(b)  The program will compile and print:

     2008
     3

(c)  The program will compile. When run, it will print:

     2008

     and throw an exception.
     
(d)  None of the above.


(b)

Note

A constructor in the enum type is called for each enum constant created, when the enum type is loaded.




PreviousNext

Related