If the object of a class is finite and fixed, such as the seasonal class, it has only 4 objects, such as a finite and fixed class, which we have in Java
is called an enumeration class.
The enumeration class is new to Java 5, which uses the enum keyword to define the enumeration class, which is a special class of clocks that can have its own field,
method, you can implement one or more interfaces, or you can define your own constructors. A maximum of one public access can be defined in a Java source file
The enumeration class for permissions. The following differences exist between enum classes and ordinary classes:
1. An enumeration class can implement one or more interfaces, and an enum class defined with an enum inherits the Java.lang.Enum class by default and does not inherit the object class.
Where the Java.lang.Enum class implements the Java.lang.Serializable and java.lang.Comparable two interfaces.
2. enum-defined, non-abstract enumerations use the final adornment by default, so the enumeration class cannot derive subclasses.
3. The constructor of an enumeration class can only use the private access control, and if the constructor's access control is omitted, the private adornment is used by default if
Enforces the specified access control, only the private modifier can be specified.
4. All instances of an enumeration class must be explicitly listed in the first row of the enumeration class, or the enumeration class will never generate an instance. When you list these instances,
The public static final decoration is automatically added without the program being explicitly added.
The following is an example of an enumeration class:
public enum Gender {MALE ("male"), FEMALE ("female");p rivate final String sex;private Gender (String sex) {this.sex=sex;} Public String Getsex () {return this.sex;}}
public class Main {public static void main (string[] args) {System.out.println (Gender.FEMALE.getSex ());}}
Output Result:
Woman
Reprint Please specify source: http://blog.csdn.net/hai_qing_xu_kong/article/details/43889967 Emotional Control _
Java Object-oriented note 9