JavaChallenge27
#SwitchCase #JavaChallenge
Try to solve the challenge by yourself first!
1. Wish You A Happy RakshaBandhan
2. A Happy RakshaBandhan
3. Wish You A
4. Compiletime error
5. Happy RakshaBandhan
Observations & Questions
1. switch() does not have any expression so, it will be executed for constant value which is 3
.
2. None of the cases has a break statement, so loop will execute all cases from the first match.
3. The default
statement is not the last case so, it can be executed or can throw compile-time error???
The position ofdefault
does not create any problem to compiler because the compiler treats the default
statement as one of the cases so it will not throw a compile-time error. Now, the obvious answer is 5
.
Let me know if you liked the challenge.