Java OCA OCP Practice Question 2103

Question

is the enum definition given below correct?.

public enum Letter {
    private int v;          // #1
    B(5), A(10), C(50);    // #2

    private Letter(int v) {
        this.v = v;
    }// w  w w . j  a  va 2  s .  co  m

    public int getValue() {
        return v;
    }
}
  • A. Yes, this enum definition is correct and will compile cleanly without any warnings or errors
  • B. no, this enum definition is incorrect and will result in compile error(s)
  • C. no, this enum definition will result in runtime exception(s)
  • D. Yes, this enum definition is correct but will compile with warnings.


B.

Note

You need to define enum elements first before any other attribute in an enum class.

in other words, this enum definition will compile cleanly if you interchange the statements marked with "#1" and "#2" within comments in this code.




PreviousNext

Related