In Java, an enum is not just a list of values — it’s actually a special kind of class.
Because of that, each enum constant can have its own behavior.
So, if you add an abstract method inside an enum, every constant must provide its own implementation.
This lets each enum value act differently.
enum Operation {
PLUS {
@Override
double apply(double x, double y) { return x + y; }
},
MINUS {
@Override
double apply(double x, double y) { return x - y; }
};
abstract double apply(double x, double y);
}
apply() is an abstract method → no body.
Each constant (PLUS, MINUS) must implement it.
This gives you polymorphism inside the enum.
You avoid writing many if or switch statements.
Each enum constant carries its own logic.
Makes the code cleaner and easier to extend.
Example:
If you want to add MULTIPLY, you just add it and implement its version of apply().
Abstract methods in enums let each enum value have its own behavior.
It’s a clean way to use polymorphism without creating many separate classes.