What will be the result of compiling and running the following code?
public enum Main { PLATINUM(20), GOLD(10), SILVER(5), BASIC; private double extra; Main(double extra) { this.extra = extra; }/* w w w.ja v a 2s . co m*/ public boolean equals(Object other) { if (this == other) return true; if (!(other instanceof Main)) return false; return Math.abs(this.extra - ((Main) other).extra) < 0.1e-5; } public static void main (String[] args) { GOLD = SILVER; System.out.println(GOLD); System.out.println(GOLD.equals(SILVER)); } }
Select the one correct answer.
(a) The program will compile and print: GOLD false (b) The program will compile and print: SILVER true (c) The program will not compile, because of 3 errors in the program. (d) The program will not compile, because of 2 errors in the program. (e) The program will not compile, because of 1 error in the program.
(c)
The program will not compile, because the method equals()
cannot be overridden by enum types.
The program will not compile, because the enum constant GOLD cannot be assigned a new value.
The constants are final.
The program will not compile, because the enum constant BASIC cannot be created, as no explicit default constructor is defined.