Sobes.tech
Junior — Middle

Can you create a subclass from an Enum type in a programming language?

sobes.tech AI

Answer from AI

In Java, it is not possible to create a subclass of the Enum type because all enums automatically inherit from the java.lang.Enum class, and Java does not support multiple inheritance of classes. Enum in Java is a special type that cannot be extended through inheritance. However, interfaces can be implemented in enums, and composition can be used to extend functionality.

Example of an enum implementing an interface:

public interface Describable {
    String getDescription();
}

public enum Status implements Describable {
    NEW {
        public String getDescription() { return "New status"; }
    },
    IN_PROGRESS {
        public String getDescription() { return "In progress"; }
    },
    DONE {
        public String getDescription() { return "Completed"; }
    };
}
Can you create a subclass from an Enum type in a… - sobes.tech