Monday, 2 April 2012

MCQ - MultiThreading


MCQ - MultiThreading

1. In java a thread can be created by ……
A. Extending the thread class
B. Implementing Runnable interface
C. Both of a and b
D. None of these

2. When a class extends the Thread class ,it should override…… method of Thread class to start that thread.
A. start()
B. run()
C. init()
D. go()



3. From the following method which method can not cause a thread  to go into a blocked state?
A.suspend()
B.yield()
C. sleep()
D.wait()

4. The default priority of a method is…….
A. 1
B. 10
C. 0
D.5

5. The highest priority of a method can be……
A. 10
B. 100
C. 5
D.1

6. The minimum priority of a thread can be……
A. 0             
B. 1
C.5
D.0.1

7. The priority of a thread can be got by……method.
A. prority()
B getPriority()
C setPriority()
D threadPriority()

8. The isAlive() method is used to…….
A. Know whether a thread is running or not
B. Know whether a thread was created or not
C. Create a thead after stopping it.
D. Resume a thread after blocking it.

9. The sleep() method can throw an…….exception.
A. ThreadException
B.InterruptedExceptoin
C. IOException
D. NullPointerException

10. To set default priority of a thread which constant can be used?
A. DEF_PRIORITY
B. DEFAULAT_PRIORITY
C. NORM_PRIORITY
D. NORMAL_PRIORITY

11. When a method is used by two threads , then it should be declare by ………keyword.
A.synchronize
B. synchronization
C.synchronized

D. shared
12.  Deadlock is a situation when ……..
A. Two or more threads have circular dependency on an object
B. Two or more threads are trying to access a same object
C.Two or more threads are waiting for a resource
D. None of these

13. To kill a thread at any stage……method is used.
A. kill()
B.stop()
C.destroy()
D.dead()

14. To resume a thread after suspendeing it…..method is used
A. resume()
B.start()
C.restart()
D. run()

15. A dead thread
A. is discarded
B. must wait until all other threads execute before it is restarted
C. can not be restarted
D. is synchronized


    Answers:

1
- C
2
- B
3
- B
4
- D
5
- A
6
- B
7
- B
8
- A
9
- B
10
- C
11
- C
12
- A
13
- B
14
- A
15
- C


No comments:

Post a Comment