+ 9
What is the difference between class & enum class in Java???
4 Réponses
+ 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
+ 4
John Champion🖤🔥 Please just paste a link to the source you are copying your answers from.
https://stackoverflow.com/questions/15734225/what-are-the-differences-between-a-java-enum-and-a-class-with-private-constructo/15734503#15734503
+ 3
David Carroll ..
Noted
+ 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