Assignment6
TYPE OF QUESTION: QUIZ
Number of questions: 10 Total mark: 10 × 1 = 10
QUESTION 1:
Which of the following is NOT a method of the Thread class in Java?
a. isAlive()
b. getPriority()
c. getNames()
d. sleep()
Correct Answer: c
Detailed Solution:
getName() is a method in the pre-defined Java class Thread but not getNames(). Other methods
like isAlive(), getPriority() and sleep() are defined in the Thread class.
QUESTION 2:
Which of the following method can be used to know the priority of a thread?
a. getPriority()
b. priority()
c. isRunning()
d. getThreadPriority()
Correct Answer: a
Detailed Solution:
getPriority() is the method, which is used to know the priority given to a thred.
, QUESTION 3:
Which of the following can be used to create an instance of Thread?
a. By implementing the Runnable interface.
b. By extending the Thread class.
c. By creating a new class named Thread and calling method run().
d. By importing the Thread class from package.
Correct Answer: a, b
Detailed Solution:
An application that creates an instance of Thread must provide the code that will run in that
thread. There are two ways to do this:
Provide a Runnable object. The Runnable interface defines a single method, run, meant
to contain the code executed in the thread. The Runnable object is passed to the Thread
constructor
Subclass Thread. The Thread class itself implements Runnable, though its run method
does nothing. An application can subclass Thread, providing its own implementation of
run
Reference:https://docs.oracle.com/javase/tutorial/essential/concurrency/runthread.html
QUESTION 4:
Which of these keywords must be used to monitor for exceptions?
a. try
b. finally
c. throw
d. catch
Correct Answer: a
Detailed Solution:
A try block must be included in a Java program to make the program robust by handling
exceptions properly.