File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unreachable statement

 
prarthana reddy
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 218
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic