定义一个枚举类型以及switch语句使用

来源:互联网 发布:大虾是什么意思网络语 编辑:程序博客网 时间:2024/04/28 19:27
public class Student {
int x;


public enum State {
ON, OFF
};// 定义一个枚举类型


public Student() {
System.out.println("无参构造函数");
}


public Student(int x) {
this.x = x;
}


public void doAction(State st) {
switch (st) {
case ON:
System.out.println("打开");
break;
case OFF:
System.out.println("关闭");
break;
}
}


public static void main(String[] args) {


new Student().doAction(State.ON);//调用方法传入一个枚举值
new Student().doAction(State.OFF);//调用方法传入一个枚举值
}
}
0 0
原创粉丝点击