Which four are true about enums?
A.
All enums implicitly implement Comparable.
B.
An enum can subclass another enum.
C.
An enum can implement an interface.
D.
An enum can declare a private constructor.
E.
An enum is typesafe.
F.
An enum cannot have public methods or fields.
A C D E
REP:A,D,E,F
public interface Operator{
int apply(int a, int b);
}
public enum SimpleOperator implements Operator{
PLUS(“plus”){
public int apply(int a, int b){return a+b;}
},
MINUS(“minus”){
public int apply(int a, int b){return a-b;}
};
private String name;
SimpleOperator(String name){
this.name = name;
}
}
public class Tester{
public static void main(String[] args){
System.out.println(SimpleOperator.PLUS.apply(2,3));
}
}
ACDE