File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Unreachable statement" Watch "Unreachable statement" New topic
Author

Unreachable statement

prarthana reddy
Ranch Hand

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

switch(i++)
{
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
Greenhorn

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: http://aspose.com/file-tools
 
subject: Unreachable statement
 
Similar Threads
What is this unreachable error
Unreachable statements
unreachable try{
code unreachable exception
Exception Doubt