Question: ```
class switch1
{
    public static void main(String args[])
    {
        int a = 10;
        switch(a)
        {
            default: System.out.println("Default");
            case -1: System.out.println("-1");
        }
    }
}

```

I understand that this program will execute both "default" and "case -1" statements as break is not specified after the matching condition (in this case after "default").

But what I fail to understand is

a) why is `break` needed in a `switch` statement?

b) why does it even execute the invalid matching conditions' statements (i.e executing "case -1")) if all it does is matching?

Answer: 
As for a., requiring the use of `break` allows shorthand notation where common code can be placed at the bottom block. This may make code more readable in some cases.

See "[Switch statement fallthrough in C#?](https://stackoverflow.com/questions/174155/switch-statement-fallthrough-in-c?lq=1)" for more information on fallthrough.

As for b., since it matches the `default` case, that line is executed. Because no `break` is present in that block, the next line is also executed regardless of a match.

Try

```
switch (a)
{
    case 10: System.out.println("This is 10.");
    case 9 : System.out.println("This is 9.");
             break;
    case 8 : System.out.println("This is 8.");
             break;
    default: System.out.println("Default");
}

```

Because there is no break in the matching case, the output is

```
This is 10.
This is 9.

```

Compare this with setting `a` to 11, 9, or 8.
a) Why fall-through / required break in switch?

The fall-through behavior is useful in some cases, but the problem is that it's extra work in the common case. Therefore it's reasonable to expect that the "break" keyword would not be required in a more modern language

So why is it there? To match the behavior of C++ (dominant language at the time Java was designed), which again matches the behavior of C (dominant language at the time C++ was designed). As for C, it (and B and BCPL, its predecessors) usually looks the way it does to make it easier to build an efficient compiler. Basically the way the switch statement works is the natural way to implement it in assembler.

b) The way it behaves follows logically from the decision to use fall-through.