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: 
> 
> a) why does a switch statement relies heavily on a break statement to achieve its purpose ?
> 
> 
> 

Because that's the way they defined it. It's copied from C. Pascal doesn't have fall-through, so it doesn't have break either. It also has case ranges, which Java lacks. Languages are allowed to be different. Or the same.

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

Because that's the way they defined it, with fall-through if you don't put a break.

> 
> if all it does is matching ?
> 
> 
> 

I don't understand the question. It doesn't do matching. It does an indexed jump to the relevant case, and falls through to the next statement if you don't put a break.
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.