Clean • Professional
In Java, ENUM is not only a list of constants — it is a full-featured data type.
Inside an enum, we can create different types of members, just like in a class.
Below are all the Enum Types (what an enum can contain or what kinds of enums exist).

A simple enum contains only constant values.
Example:
enum Color {
RED, GREEN, BLUE
}
This enum stores extra information for each constant.
Example:
enum Status {
SUCCESS(200),
ERROR(500);
private int code;
Status(int code) {
this.code = code;
}
public int getCode() {
return code;
}
}
Enums can have custom methods.
Example:
enum Level {
LOW, MEDIUM, HIGH;
public String message() {
return "Level is: " + this.name();
}
}
Each enum constant can override methods (like polymorphism).
Example:
enum Operation {
ADD {
public int apply(int a, int b) { return a + b; }
},
SUBTRACT {
public int apply(int a, int b) { return a - b; }
};
public abstract int apply(int a, int b);
}
Enums can have private constructors.
—> You cannot call new with enums.
enum Size {
SMALL("S"),
LARGE("L");
private String code;
Size(String code) {
this.code = code;
}
}
Enums can implement 1 or more interfaces.
Example:
interface Printable {
void print();
}
enum Shape implements Printable {
CIRCLE, SQUARE;
public void print() {
System.out.println(this.name());
}
}
An enum can be declared inside a class.
Example:
class Vehicle {
enum Type {
CAR, BIKE, TRUCK
}
}
Enums can contain a main() method for testing.
Example:
enum Day {
MONDAY, FRIDAY, SUNDAY;
public static void main(String[] args) {
for (Day d : Day.values()) {
System.out.println(d);
}
}
}
Enum can be used to create perfect Singleton.
enum DatabaseConnection {
INSTANCE;
}
Very common in real applications.
Example:
enum HttpStatus {
OK(200, "Success"),
BAD_REQUEST(400, "Invalid Request");
private int code;
private String message;
HttpStatus(int code, String message) {
this.code = code;
this.message = message;
}
public int code() { return code; }
public String message() { return message; }
}
| Enum Type | Description |
|---|---|
| Simple Enum | Constants only |
| Enum with Fields | Store extra data |
| Enum with Methods | Add behavior |
| Enum with Abstract Methods | Different behavior per constant |
| Enum with Constructor | Initialize constants |
| Enum Implementing Interface | Add contract |
| Nested Enum | Enum inside class |
| Enum with main() | Runnable enum |
| Enum Singleton | Best Singleton |
| Enum with Multiple Fields | Complex domain models |