Page 1 of 1

About Question com.enthuware.ets.scjp.v6.2.668 :

Posted: Sun Jan 30, 2011 5:53 pm
by ETS User
Which statements regarding the following code are correct?

Code: Select all



class A extends Thread
{
	public void run()
	{
		System.out.println("Starting loop");
		while(true){}; //1
		System.out.println("Ending loop");
	}
}
public class TestClass
{
	public static void main(String args[]) throws Exception
	{
		A a = new A();
		a.start();
		Thread.sleep(1000);
		a.interrupt();
	}
}
One of the correct answers identified is:
This will not compile.
Because System.out.println("Ending loop"); is unreachable.
This may be true but I selected this answer because I understand that a call to sleep() should be placed in a Try/Catch block, which this code does not have. Can you please confirm this?

The other correct answer is:
It will run and end cleanly if //1 is replaced with while(!isInterrupted()) { };
According to the SCJP Study Guide by Sierra and Bates, interrupt() and isinterrupted() are not included in a list of methods that one needs to know for this exam.

Re: About Question com.enthuware.ets.scjp.v6.2.668 :

Posted: Sun Jan 30, 2011 8:01 pm
by admin
Hello,
The main method has a throws clause..."throws Exception". So the call to sleep() need not be put within try/catch.

Regarding whether it is required for the exam...a few topics might be on the borderline and we believe it is better to know about them than to be surprised in the exam.

HTH,
Paul.