← Back to libraryQuestion 44 of 273
JavaBeginner

Java Enums

📖 Detailed Explanation:

Enums are special classes representing a fixed set of constants. They are type-safe (unlike static final int), can have their own fields/methods, and can implement interfaces. Each enum constant is a singleton instance of the enum class. Enums are thread-safe by design.

🌍 Real-World Example:

Days of the Week: public enum Day { MONDAY, TUESDAY, ..., SUNDAY; } You can't accidentally pass 'Day 8' because only 7 values exist.

🎯 Scenario-Based Interview Question:

Why is an Enum Singleton considered the BEST way to implement Singleton in Java?