(2) and (3) are incorrect because they are methods of the Object class. (5) is incorrect because there's no such method in any thread-related class.
(3), (4), and (5) are not legal Thread constructors, although (4) is close. If you reverse the arguments in (4), you'd have a valid constructor.
(5) is correct because sleep() will always pause the currently running thread for at least the duration specified in the sleep argument (unless an interrupted exception is thrown).
(6) is correct because, assuming that the thread you're calling join() on is alive, the thread calling join() will immediately block until the thread you're calling join() on is no longer alive.
(1) is wrong, but tempting. The yield() method is not guaranteed to cause a thread to leave the running state, although if there are runnable threads of the same priority as the currently running thread, then the current thread will probably leave the running state.
(3) and (4) are incorrect because they don't cause the thread invoking them to leave the running state.
(7) is wrong because there's no such method.
class X implements Runnable { public static void main(String args[]) { /* Missing code? */ } public void run() {} }
(3), (5), (7), and (8) are incorrect answers. The methods isInterrupted() and interrupt() are instance methods of Thread.
The methods sleep() and yield() are static methods of Thread.
D is incorrect because synchronized is a keyword and the synchronized() construct is part of the Java language.
Option A is wrong. The run() method of a thread is like the main() method to an application. Starting the thread causes the object's run method to be called in that separately executing thread.
Option B is wrong. There is no construct() method in the Thread class.
Option D is wrong. There is no register() method in the Thread class.
Option A and D are incorrect because they are narrowing the access privileges i.e. package(default) access is narrower than public access.
Option C is not method in the Runnable interface therefore it is incorrect.
Option B is wrong. wait() causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object.
Option C is wrong. Methods of the InputStream class block until input data is available, the end of the stream is detected, or an exception is thrown. Blocking means that a thread may stop until certain conditions are met.
Option D is wrong. sleep() - Causes the currently executing thread to sleep (temporarily cease execution) for a specified number of milliseconds. The thread does not lose ownership of any monitors.
Option B, C, and D are incorrect because they do not define these methods. And yes, the Java API does define a class called Class, though you do not need to know it for the exam.
Option B is wrong. The start() method causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.
Option C is wrong. The stop() method is deprecated. It forces the thread to stop executing.
Option D is wrong. Is the main entry point for an application.
Comments
There are no comments.Copyright ©CuriousTab. All rights reserved.