jQuery in Action, 2nd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Threads" Watch "Threads" New topic
Author

Threads

Tanuja Vaid
Ranch Hand

Joined: Mar 07, 2002
Posts: 51
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

Joined: Mar 07, 2002
Posts: 51
I GOT IT!
SAVED U GUYS A TROUBLE
Arun Pai
Ranch Hand

Joined: Mar 11, 2002
Posts: 143
Tanuja, What's the answer?
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2573

Statement on line //1 is an infinite loop which will not terminate, hence staement //3 is unreachable.
HTH,
- Manish
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Threads
 
Similar Threads
Can't understand this tricky for loop question
continue statement
for loop -- break \ continue statement
for loop problem
break lable problem