Threads

Q1:
Which three are methods of the Object class?
  1. notify();
  2. notifyAll();
  3. isInterrupted();
  4. synchronized();
  5. interrupt();
  6. wait(long msecs);
  7. sleep(long msecs);
  8. yield();

A 1, 2, 4

B 2, 4, 5

C 1, 2, 6

D 2, 3, 4

Q2:
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

Q3: What is the name of the method used to start a thread execution?

A init();

B start();

C run();

D resume();

Q4: Which of the following will not directly cause a thread to stop?

A notify()

B wait()

C InputStream access

D sleep()

Q5:
Which three guarantee that a thread will leave the running state?
  1. yield()
  2. wait()
  3. notify()
  4. notifyAll()
  5. sleep(1000)
  6. aLiveThread.join()
  7. Thread.killThread()

A 1, 2 and 4

B 2, 5 and 6

C 3, 4 and 7

D 4, 5 and 7

Q6:
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

Q7:
class X implements Runnable 
{ 
    public static void main(String args[]) 
    {
        /* Missing code? */
    } 
    public void run() {} 
}
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();

Q8:
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

Q9: Which of the following will directly stop the execution of a Thread?

A wait()

B notify()

C notifyall()

D exits synchronized code

Q10: Assume the following method is properly synchronized and called from a thread A on an object B: wait(2000); After calling this method, when will the thread A become a candidate to get another turn at the CPU?

A After thread A is notified, or after two seconds.

B After the lock on B is released, or after two seconds.

C Two seconds after thread A is notified.

D Two seconds after lock B is released.

Q11: 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)

Q12: Which will contain the body of the thread?

A run();

B start();

C stop();

D main();

Q13: Which class or interface defines the wait()notify(),and notifyAll() methods?

A Object

B Thread

C Runnable

D Class

Q14:
public class MyRunnable implements Runnable 
{
    public void run() 
    {
        // some code here
    }
}
which of these will create and start this thread?

A new Runnable(MyRunnable).start();

B new Thread(MyRunnable).run();

C new Thread(new MyRunnable()).start();

D new MyRunnable().start();

Q15: Which cannot directly cause a thread to stop executing?

A Calling the SetPriority() method on a Thread object.

B Calling the wait() method on an object.

C Calling notify() method on an object.

D Calling read() method on an InputStream object.

Q16: Which method registers a thread in a thread scheduler?

A run();

B construct();

C start();

D register();


img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.