Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads

 
Tanuja Vaid
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lass A extends Thread
{
public void run()
{
System.out.println("Starting loop");
while(true){}; //1
System.out.println("Ending loop");//3
}
}
public class TestClass
{
public static void main(String args[]) throws Exception
{
A a = new A();
a.start();
Thread.sleep(1000);
a.interrupt();
}
}
The above code when compiled gives an error saying line 3 is an unreachable statement.
Can anybody explain why?
Thanks in Advance.
Tanuja
 
Tanuja Vaid
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I GOT IT!
SAVED U GUYS A TROUBLE
 
Arun Pai
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tanuja, What's the answer?
 
Manish Hatwalne
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Statement on line //1 is an infinite loop which will not terminate, hence staement //3 is unreachable.
HTH,
- Manish
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic