Junior — Middle
Can an enumerable type implement an interface in a programming language?
sobes.tech AI
Answer from AI
Yes, in Java, an enum type can implement interfaces. This allows defining a common contract for all enum constants and provides polymorphism. For example:
interface Printable {
void print();
}
enum Day implements Printable {
MONDAY, TUESDAY, WEDNESDAY;
@Override
public void print() {
System.out.println(this.name());
}
}
In this example, each enum value of Day implements the print() method from the Printable interface.