As I saw the following question in the above mentioned book by Scott Selikoff and Jeanne Boyarsky:
Which of the following statements about a default branch in a switch statement is correct?
and the following answers:
A. All switch statements must include a default statement.
B. The default statement is required to be placed after all case statements.
C. Unlike a case statement, the default statement does not take a value.
D. A default statement can only be used when at least one case statement is present.
I knew that A, B and D are incorrect. In this case C is correct.
But the thing is, that I'am a little bit frustrated:
Nowhere in my many Java books on OCA exam is there any mention that "default" statement does not take a value!!! Nor I find some interesting note in the internet. Or is this an intention to exclude the incorrect answers?
Can anybody tell me, where I can find such a statement about the default statement in switch statements, that only in the default statement a value is not necessary!
I saw many questions in different books or including cd exam questions or mock exam questions that give answers which I couldn't read nowhere!!! Why I read books about the OCA exam and many important things are not explained?!
I learn these Java statements only by answering these questions.
Here are some important resources to learn more about switch statements: JLS and from the Oracle tutorials but you might have already encountered those during your own searches.
It is important to understand what the default case does. It basically says (in simple terms): if none of the other specified cases apply, then do 'this' (i.e. which is whatever you have included as logic). So why would you want to add a value to the default statement? If you want a certain action to be done for a specified case value, you need a regular case statement.
I am wondering... If you'd specify a value for the default block, then what would that even mean?