in java, all enum types that we created are final classes that inherits Enum class. so why does java allow us to declare an abstract method in our enum types ? because an enum type is a final class, and java doesn't allow us to declare an abstract method in final classes.
Thanks.
You are not expected to extend them, but you could certainly implement an abstract method many times:
public enum Animal {
COW {
public String talk() {
return "moo";
}
},
FROG {
public String talk() {
return "croak";
}
};
public abstract String talk();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With