87.2k views
1 vote
What's the difference between an enum's constructor and a regular class constructor?

A. Enums don't have constructors.
B. Enums may only have one constructor while regular classes may have more than one.
C. Enum constructors must be private while regular class constructors are public.
D. Enum constructors and regular class constructors are the same.

User Vectrobyte
by
7.9k points

1 Answer

5 votes

Final answer:

Enums don't have constructors, enums may only have one constructor while regular classes may have more than one, and enum constructors must be private while regular class constructors are public.

Step-by-step explanation:

The difference between an enum's constructor and a regular class constructor is that:

  • Enums don't have constructors. Unlike regular classes, enums cannot have explicit constructors defined by the programmer. Instead, the Java compiler automatically generates a default constructor for enums.
  • Enums may only have one constructor while regular classes may have more than one. Regular classes can have multiple constructors with different parameters, allowing for different ways to create objects. Enums, on the other hand, have a single constructor generated by the compiler.
  • Enum constructors must be private while regular class constructors are public. The constructor generated for an enum is always private, ensuring that enum instances cannot be created from outside the enum class. Regular class constructors, by default, are public, allowing instances to be created from any class or package.

User JaakkoK
by
8.8k points