Dave Malcolm wrote:I repeat that if what you're both saying is true then the book is awful because this is supposed to prepare people for the exam.
Yes, it's an unfortunate mistake. I believe it was already discussed on this forum before, so it might be corrected in a future edition.
Mikalai Zaikin wrote:A switch can be an expression or a statement (it can be decided by the compiler by looking if the case block returns anything)
A small correction here. The compiler doesn't determine whether the switch is a statement or expression by looking at the switch block. The compiler simply
expects a statement or an expression at the current location.
You can very easily do this
test for yourself by replacing the entire switch with a simple expression, say
"Winter".
In
printSeason(), using an expression leads to invalid code, so the switch must be a statement.
In
printSeason2(), the code remains valid if we replace the switch with a simple expression. Therefore, the switch is a switch expression.