Multithreading (each question carries two marks)

Output is
A.1
B.Nothing will be printed
C.Runtime exception will be thrown
D.1 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
Which of the following line of code is suitable to start a thread ?
A. Thread t = new Thread(X);
B. Thread t = new Thread(X); t.start();
C. X run = new X(); Thread t = new Thread(run); t.start();
D. Thread t = new Thread(); x.run();
Which two of the following methods are defined in class Thread?1. start() 2. wait() 3. notify() 4. run() 5. terminate()
A. 1 and 4
B. 2 and 3
C. 3 and 4
D. 2 and 4
Which of the following will directly stop the execution of a Thread?
A. wait()
B. notify()
C. notifyall()
D. Exits synchronized code
Which method must be defined by a class implementing the java.lang.Runnable interface?
A. Void run()
B. Public void run()
C. Public void start()
D. Void run(int priority)
Which will contain the body of the thread?
A. run();
B. start();
C. stop();
D. main();
Which method registers a thread in a thread scheduler?
A. run();
B. construct();
C. start();
D. register();
How can Thread go from waiting to runnable state?
A. notify/notifAll
B. When sleep time is up
C. Using resume() method when thread was suspended
D. All
What is difference between starting thread with run() and start() method?
A. There is no difference
B. When you call start() method, main thread internally calls run() method to start newly created Thread
C. run() calls start() method internally
D. None
Which method restarts the thread
A. start()
B. restart()
C. restartThread()
D. none
What will happen if two threads try to write to same resource without synchronization in java
A. It is not allowed in java
B. It doesn't create any race condition
c. It will create race condition
D. None
How many threads can a process contain?
A. 1
B. 2
C. multiple
D. none
Which is thread safe?
A. StringBuffer
b. StringBuilder
C. All
D. None
How can you ensure all threads that started from main must end in order in which they started and also main should end in last
A. join() method
B. sleep() method
C. wait() method
D. run() method
What is valid about threads
A. Threads have their own heap allocated area.
b. Threads have their own stack.
C. Threads doesn't have own stack.
D. None
What are valid statements about Constructor and synchronization in java?
A. We can enclose constructor in try-catch block
b. We can use use synchronized code in constructor
c. Constructor can be synchronized
D. None
What are valid statements for yield method?
A. yield() method when called on thread gives a hint to the thread scheduler that the current thread is willing to yield its current use of a processor. The thread scheduler is free to ignore this hint.
B. yield() method stops thread for unpredictable time.
C. yield() is a static method, hence calling Thread.yield() causes currently executing thread to yield.
D. All
What is minimum thread priority in java?
A. -1
B. 0
C. 1
D. 5
What are valid statements for daemon threads?
A. User created threads are non daemon threads.
B. JVM can exit when only daemon threads exist in system.
c. Daemon threads are low priority threads which runs intermittently in background for doing garbage collection.
D. All of these
{"name":"Multithreading (each question carries two marks)", "url":"https://www.quiz-maker.com/QPREVIEW","txt":"output is, 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), Which of the following line of code is suitable to start a thread ?","img":"https://cdn.poll-maker.com/8-395418/q5.png?sz=1200-000000100053"}
Powered by: Quiz Maker