What is the difference between class & enum class in Java??? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 9

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

20th May 2019, 3:41 AM
Nasirā¤
Nasirā¤ - avatar
4 Respostas
+ 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