Object generation question in JAVA/enum class.

Asked 2 years ago, Updated 2 years ago, 28 views

This is my first time studying Java I have a question while listening to the Java introduction lecture in programmers.

enum Gender{ MALE, FEMALE; }// define enumeration

Gender gender2;//<-enum class name object name;

gender2 =Gender.MALE;
gender2 =Gender.FEMALE;

//Use enumeration when it comes to

enum class name object name; He created and created an object called a gender I think they initialized the gender object with the constant defined by enum class In enum class, we don't use new enum class name object name; Is it a way to create an enum class object by declaring it as? How objects are created in the enum class I'm asking because I want to know.

java

2022-09-22 19:16

1 Answers

As far as I know, each instance is created as much as the constant defined in the compilation stage, and these instances are contained in static variables defined as static final and can be used as a single ton form.


2022-09-22 19:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.