1.What is the name of the method used to start a thread execution?
A.  init(); B.  start();
C.  run(); D.  resume();
Answer & Explanation
Answer: Option B
Explanation:
Option B is Correct. The start() method causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.
Option A is wrong. There is no init() method in the Thread class.
Option C 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 D is wrong. The resume() method is deprecated. It resumes a suspended thread.
2.Which two are valid constructors for Thread?
   1. Thread(Runnable r, String name)
   2. Thread()
   3. Thread(int priority)
   4. Thread(Runnable r, ThreadGroup g)
   5. Thread(Runnable r, int priority)
A.  1 and 3 B.  2 and 4
C.  1 and 2 D.  2 and 5
Answer & Explanation
Answer: Option C
Explanation:
(1) and (2) are both valid constructors for Thread.
(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.
 
 
No comments:
Post a Comment