package java_test; class aaa{ String name; public aaa(String name){ this.name=name; } public void test(){ int a=3; switch (a){ case 1: System.out.println("a为1"); break; case 2: System.out.println("a为2"); break; case 3: System.out.println("a为3"); break; default: System.out.println("haha"); break; } } } public class Hero { public static void main(String[] args) { aaa a=new aaa("hh"); System.out.println(a.name); } }
1.哪条case满足了,就从哪条case开始执行,一直执行到break或者执行到switch结束
2.答案的书写没有顺序
3.switch支持数据类型为:byte、short、char、int、String、枚举