Java OCA OCP Practice Question 3162

Question

Is the enum definition given below correct?
public enum PrinterType {
     private int pagePrintCapacity;          // #1
     DOTMATRIX(5), INKJET(10), LASER(50);    // #2

     private PrinterType(int pagePrintCapacity) {
             this.pagePrintCapacity = pagePrintCapacity;
     }//from w w  w .j  a v a  2s .c om

     public int getPrintPageCapacity() {
             return pagePrintCapacity;
     }
}
  • 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