An enumeration class should be written as a class.
"1, 2,3" is a data type, which is neither an object nor a variable. Must be reported as an error.
The following is an explanation taken from the Internet. Please have a look.
Enumeration:
1. adds Java 5, which is a class type, but new cannot be used.
You can't inherit from other classes, and you can't be a superclass, that is, you can't extend. But you can implement this interface by implicitly inheriting the java.lang.Enum class.
2. Enumeration includes two predefined methods:
Public static enumeration type [] value ();
Public static enumeration type valueof (stringst); Used in a for-each loop to iterate through enumerated constants.
And "= =" can be used to judge whether two enumeration constants are equal.
There are three ways to inherit from Enum:
Final ordinal ()-Returns a constant ordinal value.
Final int compare to(enum-type e)- the comparison order of values in the same enumeration.
The final Boolean equals (enum-type e)- whether they are equal in the same enumeration is equivalent to "= =".
3. In the switch representation, the case statement does not need and cannot add enumeration types, otherwise an error will occur.
4. Enumeration is a class type, which can define constructors and overloads, as well as other instance methods and variables. Each of these enumerated constants has its own copy, and even static members can be defined and interfaces can be implemented.
Such as: public enumeration response implementation do response {
Perfect (10), good (8), fair (5), poor (2), terrible; //Enumeration constants, equivalent to public static answer types.
public static int type = 1; //Define static members
Private int degree; //Define instance member variables
Private Answer(){ // defines a constructor with no parameters. Comments can only be private, and the default is the same.
Degree =-1;
}
Private Answer(int d){ // defines an overloaded constructor with parameters.
Degree = d;;
}
The public string getProblem(){ // implements the interface method.
Return to DoAnswer. Problems;
}
Public int getDegree(){ // defines an instance member function.
Regression degree;
}
The public answer getAnswer(){ // defines a member function that returns itself, and each constant has its own copy.
Return this;
}
}