+ 9

What is the difference between class & enum class in Java???

20th May 2019, 3:41 AM
Nasir❀
Nasir❀ - avatar
4 Answers
+ 4
Md. Nasir Uddin In Java, a class can only extend one parent and therefore an enum cannot extend any other class (but implement interfaces). Extending Enum means that every enum has a few methods that make it more usable: static values() static valueOf(String) source: https://www.sitepoint.com/fundamentals-of-java-enum-types-tutorial/ I hope I was helpful
20th May 2019, 3:52 AM
Alessio Benvenuti
Alessio Benvenuti - avatar
+ 3
David Carroll .. Noted
20th May 2019, 5:18 AM
TroyđŸŒč
TroyđŸŒč - avatar
+ 1
Enums extend java.lang.Enumand gain all of its nice features: Automatic singleton behaviour through correct serialization Automatic human-readable .toString method on enum values without the need to duplicate your enum names .name and .ordinal special-purpose methods Usable in high-performance bitset-based EnumSet and EnumMap classes Enums are treated by the language specially: Enums use a special syntax which simplifies instance creation without writing dozens of public static final fields Enums can be used in switch statements Enums cannot be instantiated outside the enumeration list except by using reflection Enums cannot be extended outside the enumeration list Java automatically compiles extra stuff into enums: public static (Enum)[] values(); public static (Enum) valueOf(java.lang.String); private static final (Enum)[] $VALUES;(values() returns a clone of this) Most of these can be emulated with a suitably designed class, but Enumjust makes it really easy to create a class
20th May 2019, 4:39 AM
TroyđŸŒč
TroyđŸŒč - avatar