This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Unreachable statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Unreachable statement" Watch "Unreachable statement" New topic

Unreachable statement

prarthana reddy
Ranch Hand

Joined: Jul 24, 2006
Posts: 48
public class Test
public static void main(String args[])
int i = 1;

case 0:

System.out.print(i + " "); //1
break; //2
System.out.print(i + " "); //3

case 1: //4

System.out.print(i + " ");
default: //5

I dont understand why print statement in case 1 is unreachable ..
nivas ratthaaq

Joined: Aug 15, 2006
Posts: 18
Every statement under switch should come under 'case' or 'default'.I think,due to the break statement, irrespective of condition in switch statement,it is not possible to reach the '..print' statement.
Aniket Patil
Ranch Hand

Joined: May 02, 2006
Posts: 218
It is not the print statement of case 1 that is unreachable, but print statement marked with "//3". The reason for this is given above.

SCJP 5.0 | SCWCD 1.4 <br /> <br />If you don't know where you are going, any road will take you there!
I agree. Here's the link:
subject: Unreachable statement
It's not a secret anymore!