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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
ETS User

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

Post 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.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 53 guests