Module 14: Enums and Annotations
Enums with Fields and Behavior
Add fields and methods to enums so each constant can carry real behavior.
Author
Java Learner Editorial Team
Reviewer
Technical review by Java Learner
Last reviewed
2026-04-17
Java version
Java 25 LTS
Learning goals
- Add fields and constructors to enums
- Use enum methods to keep behavior close to the state
- Recognize when enums can replace scattered branching
Enums can do more than list constants: They can have fields, constructors, and methods just like classes.
This makes them useful for domain modeling: A ticket status can carry a label, a color code, or next-step rules.
Behavior close to the enum often beats scattered condition chains elsewhere: That keeps the rules visible in one place.
Keep the enum focused: If it turns into a giant god-object, the design has gone too far.
Runnable examples
Each enum constant carries a label
enum Priority {
LOW("Low"), HIGH("High");
private final String label;
Priority(String label) {
this.label = label;
}
public String label() {
return label;
}
}
System.out.println(Priority.HIGH.label());Expected output
High
Mini exercise
Add a human-readable label field to an enum you already created.
Summary
- Enums can carry data and behavior.
- That often keeps small domain rules tidy.
- Use this power carefully so enums stay focused.
Next step
After enums, learn the built-in annotations that shape everyday Java code.
Sources used