feat(class26): 补枚举类提交

- 新增枚举类 A,包含 X、Y、Z 三个枚举值
- 添加测试类 Test,演示枚举类的使用方法
- 说明枚举类的主要特征:
  - 1.枚举类是 final 的 - 2. 枚举类不能继承其他类
  -3. 枚举类对象是固定的,不能创建新的对象
This commit is contained in:
2025-07-17 23:50:18 +08:00
parent baefa25e78
commit da8ed0e2b5
2 changed files with 26 additions and 0 deletions

11
src/class26/A.java Normal file
View File

@@ -0,0 +1,11 @@
package class26;
public enum A {
X,Y,Z;
//枚举类特征:
//1.枚举类是final的
//2.枚举类不能继承其他类
//3.枚举类对象是固定的,不能创建新的对象
}

15
src/class26/Test.java Normal file
View File

@@ -0,0 +1,15 @@
package class26;
import java.util.Arrays;
public class Test {
public static void main(String[] args) {
A a1 = A.X;
System.out.println(a1);
System.out.println(Arrays.toString(A.values()));
System.out.println(a1.ordinal());//索引
}
}