01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
package enumeration2;

public enum Op {
  ADD("+") { public int eval(int x, int y) { return x + y; } },
  SUB("-") { public int eval(int x, int y) { return x - y; } },
  MUL("*") { public int eval(int x, int y) { return x * y; } },
  DIV("/") { public int eval(int x, int y) { return x / y; } };

  private final String name;
  private Op(String name) { this.name = name; }

  public String toString() { return name; }
  public abstract int eval(int x, int y);
}