class switch1
{
public static void main(String args[])
{
int a = 10;
switch(a)
{
default: System.out.println("Default");
case -1: System.out.println("-1");
}
}
}
我知道这个程序在匹配条件(在这种情况下是“default”后)没有指定break时会同时执行“默认”和“case -1”的语句。
但我不明白的是:
a)为什么在switch语句中需要使用break?
b)如果它只是匹配条件,为什么会执行无效匹配条件的语句(即执行“case -1”)?