• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

OCA/OCP Java SE 8 Programmer Practice Tests, Chapter 3, Question 5, page 35

 
Ranch Hand
Posts: 73
1
Mac IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

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.

Thank you for your interesting answers.
 
Rancher
Posts: 261
12
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mike,

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?
 
Marshal
Posts: 74044
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you ever looked at the Java® Language Specification? It includes this part of its grammar:-

SwitchLabel:
    case ConstantExpression :
    case EnumConstantName :
    default :

That tells you that there is nothing following the default keyword, only the “:”.
 
author & internet detective
Posts: 40747
827
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's covered on page 73 of our (Sybex's) OCA book.

The practice tests book isn't meant to be used in isolation> It's meant to complement an OCA study guide. Not sure which one of those you are using.
 
What's that smell? Hey, sniff this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic