混淆 枚举
让我们从枚举开始……(Let’s begin with enum …)
The following are important points about enum :
以下是有关枚举的要点:
An enum is a group of predefined named constant in any programming language.
枚举是任何编程语言中的一组预定义的命名常量。
- Enum is used when we know all possible values of the group before compiling the code. 当我们在编译代码之前知道该组的所有可能值时,将使用Enum。
Example: Direction can be an enum as we know all possible values of direction that can be NORTH, SOUTH, EAST, and WEST and declared using the enum keyword.
示例: Direction可以是一个枚举,因为我们知道了Direction的所有可能值,可以是NORTH,SOUTH,EAST和WEST,并使用 枚举关键字。
Over the course of development, we may add a few new enum constant.
在开发过程中,我们可能会添加一些新的枚举常量。
Enums are very powerful as they may have instance variables, instance methods, and constructors.
枚举非常强大,因为它们可能具有实例变量,实例方法和构造函数。
Each enum constant should be written in capital letters.
每个枚举常量都应以大写字母表示。
Every enum constant is by default internally public static final of type Enum declared.
我们来看一个枚举的例子: (Let’s see an example of enum :)
输出:(OUTPUT :)
Direction name : NORTHDirection name : SOUTHDirection name : WESTDire