Look at this program and predict the output:
public class Main { PrinterType printerType;//from w ww.j a v a2s . co m enum PrinterType {INKJET, DOTMATRIX, LASER}; public Main(PrinterType pType) { printerType = pType; } public static void main(String[] args) { PrinterType pType = new PrinterType(); Main enumTest = new Main(PrinterType.LASER); } }
A.Prints the output printerType:LASER. B.Compiler Error: enums must be declared static. C.Compiler Error: cannot instantiate the type Main.PrinterType. D.This program will compile fine, and when run, will crash and throw a runtime exception.
C.
You cannot instantiate an enum type using new.