package Class_study; public enum Operation {//枚举类+内部类+抽象函数 Divide{ public double eval(double x,double y){ return x/y; } },Pluse{ public double eval(double x,double y){ return x-y; } },Add{ public double eval(double x,double y){ return x+y; } },Minus{ public double eval(double x,double y){ return x*y; } }; abstract public double eval(double x ,double y); public static void main(String args[]){ System.out.println(Operation.Add.eval(2, 7)); System.out.println(Operation.Add.eval(8, 8)); } }
每个枚举对象对应自己的方法
时间: 2024-09-29 17:18:32