Java Multithreading and Exception Handling

Java Multithreading and Exception Handling

28 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Which of the following methods is/are correct for making a new thread?
A. Declare a class to be a subclass of Thread class.
B. Declare a class that implements the Runnable class.

  1. Only A
  2. Only B
  3. Both A and B
  4. Neither A nor B
Question 2 Multiple Choice (Single Answer)

The code we want to execute has to be placed in a method ________ of the class which extends class Thread.

  1. start()
  2. run()
  3. first()
  4. exec()
Question 3 Multiple Choice (Single Answer)

Which one of the following is the correct structure to create and run a thread?

  1. class MyClass extends Runnable
    {
    public void run()
    {
    }
    }
  2. class MyClass implements Thread
    {
    public void run()
    {
    }
    }
  3. class Thread MyClass
    {
    public void run()
    {
    }
    }
  4. class MyClass extends Thread
    {
    public void run()
    {
    }
    }
Question 4 Multiple Choice (Single Answer)

Which one of the following is not a correct state for life cycle of a thread?

  1. Ready
  2. Blocked
  3. Return
  4. Dead
Question 5 Multiple Choice (Single Answer)

When an allocated time of a thread is over, JRE puts it back in the _____ state.

  1. new
  2. ready
  3. running
  4. dead
Question 6 Multiple Choice (Single Answer)

Which one of the following is not a valid thread priority constant?

  1. MAX_PRIORITY
  2. MIN_PRIORITY
  3. NORM_PRIORITY
  4. AVG_PRIORITY
Question 7 Multiple Choice (Single Answer)

FirstTh th=new FirstTh();
Thread sm=new Thread(th).start();
Which of the following statements is correct with respect to the above code?

  1. FirstTh is a simple class.
  2. FirstTh is a class that inherits from Thread class.
  3. FirstTh is a class that implements from Thread class.
  4. FirstTh is a class that implements Runnable interface.
Question 8 Multiple Choice (Single Answer)

Which of the following methods makes the current thread to wait until other specified thread terminates?

  1. wait()
  2. join()
  3. notify()
  4. delay()
Question 9 Multiple Choice (Single Answer)

The methods wait(), notify() and notifyAll() must be called only when they own the monitor of that object, otherwise they throw __________________.

  1. IllegalMonitorException
  2. IllegalStateException
  3. IllegalMonitorStateException
  4. IllegalMonitorOwnStateException
Question 10 Multiple Choice (Single Answer)

The class Timer and TimerTask are available in the package __________.

  1. java.awt
  2. java.swing
  3. java.math
  4. java.util
Question 11 Multiple Choice (Single Answer)

Which one of the following is not a valid constructor of Timer class?

  1. Timer()
  2. Timer(Boolean isDaemon)
  3. Timer(String name)
  4. Timer(char[] name)
Question 12 Multiple Choice (Single Answer)

What is the use of purge() method in Timer class?

  1. Terminate this Timer
  2. Schedule the specified task for execution at the specified time
  3. Remove all cancelled tasks from this timer’s task queue
  4. Remove all running tasks from this timer’s task queue
Question 13 Multiple Choice (Single Answer)

Which of the following statements is/are correct?
A. The sleep() method is used to permanently stop the execution of the thread.
B. The join() method is used to wait for this thread to die.

  1. Only A
  2. Only B
  3. Both A and B
  4. Neither A nor B
Question 14 Multiple Choice (Single Answer)

Suppose a thread wants some input data. It cannot continue unless it is made available by the OS. Such a state is called a _________ state.

  1. ready
  2. blocked
  3. running
  4. dead
Question 15 Multiple Choice (Single Answer)

What is the use of destroy() method of thread class?

  1. Destroy this thread, without any clean-up
  2. Destroy this thread, with clean-up
  3. Destroy all threads, without any clean-up
  4. Destroy all threads, with clean-up
Question 16 Multiple Choice (Single Answer)

Which of the following correctly represents the exception?

  1. Compile error
  2. Syntax error
  3. Runtime error
  4. Not an error
Question 17 Multiple Choice (Single Answer)

Which of the following packages defines a class Throwable?

  1. java.awt
  2. java.swing
  3. java.lang
  4. java.util
Question 18 Multiple Choice (Single Answer)

Throwable class has two sub-classes, ________ and __________.

  1. Errors and Exceptions
  2. Error and Exceptions
  3. Errors and Exception
  4. Error and Exception
Question 19 Multiple Choice (Single Answer)

Java has defined a _______________ class which is a super-class for all runtime error classes.

  1. RuntimeExceptions
  2. RuntimeException
  3. Exception
  4. Throwable
Question 20 Multiple Choice (Single Answer)

The code which is likely to produce exception is kept within the ___________ block.

  1. catch
  2. try
  3. throw
  4. main()
Question 21 Multiple Choice (Single Answer)

A block labelled as finally will _________.

  1. never execute
  2. always execute
  3. execute if catch block will execute
  4. execute if catch block will not execute
Question 22 Multiple Choice (Single Answer)

The throw statement is used to throw the _____ type exception.

  1. class
  2. data
  3. object
  4. methods
Question 23 Multiple Choice (Single Answer)

Which of the following exceptions occurs, if one is trying to access an element of array with an index that is larger than the range?

  1. ArrayIndexOutOfBoundsException
  2. ArrayIndexOutOfBoundsExceptions
  3. ArrayIndexOutOfBoundException
  4. ArrayOutOfBoundsException
Question 24 Multiple Choice (Single Answer)

Which of the following exceptions is not a sub-class of RuntimeException?

  1. ArithmeticException
  2. ArrayStoreException
  3. SecurityException
  4. ClassCastException
Question 25 Multiple Choice (Single Answer)

An instance of ThreadDeath is thrown in the victim thread when the stop method is called with ____ arguments.

  1. 0
  2. 1
  3. 2
  4. 3
Question 26 Multiple Choice (Single Answer)

Which of the following statements is/are correct?
A. A finally block is optional.
B. throw and throws are the same.

  1. Only A
  2. Only B
  3. Both A and B
  4. Neither A nor B
Question 27 Multiple Choice (Single Answer)

What is the return type of start() method of class Thread?

  1. int
  2. void
  3. char
  4. static void
Question 28 Multiple Choice (Single Answer)

In Java, the concept of synchronisation is based on the concept of ___________.

  1. thread
  2. explicit lock
  3. intrinsic lock
  4. deadlock