This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes switch? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "switch?" Watch "switch?" New topic


achayya matta
Ranch Hand

Joined: Oct 27, 2005
Posts: 111
can anyone clarify me why the following code prints 3,4?

switch (2) {

case 1:


case 2:

case 3:


case 4:



thanks in advance
Ricky Ignatius

Joined: Oct 09, 2005
Posts: 20
switch (2) {
case 1:
case 2: // inside here, no break
case 3: // fall throught here, no break
case 4: // fall throught here, no break

Because the code will go inside case 2 then fall through to case 3, case 4 because they dont have break statement.

Gyanesh Sharma
Ranch Hand

Joined: Nov 27, 2005
Posts: 47
Because there is no break; statements in your code sample.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: switch?
It's not a secret anymore!