File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
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 agree. Here's the link:
subject: switch?