1. Which of the following is NOT a method of the Thread class in Java?
a. isInterrupted()
b. interrupt ()
c. joins ()
d. sleep()
2. Which of the following statement(s) is/are true?
a. public int getId(): returs the id of the thread.
b. public boolean isAlive(): tests if the thread is alive.
c. public void interrupt(): interrupts the thread.
d. public boolean isInterrupted() : tests if the thread has been interrupted.
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.
4. What is the output of the following program?
public class Question
{
public static void main(String[] args) {
try{
int a=5/0;
} catch (Exception e) {
catch (ArithmeticException a) {
}
}
System.out.println("Hello World");
}
}
a. Hello World
b. 5
c. Compile time error
d. ArithmeticException
5. Which one of these keywords must be used to handle the exception thrown by try block in some rational manner?
a. try
b. finally
c. throw
d. catch
6. 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) Two seconds after thread A is notified.
c) After the lock on B is released, or after two seconds.
d) Two seconds after lock B is released.
7. The following is a simple program using the concept of thread.
public class Question extends Thread{
public void run(){
for(int i=1;1<5;itt+){
System.out.println (i++);
}
}
public static void main(String args[]) {
Question ti=new Question ();
t1.run();
}
}
What is the output of the above program?
a. 1
3
b. 1
2
3
4
c. Runtime error
d. 1
2
8. For the program given below, what will be the output after its execution?
public class Main{
public static void main(String[Jargs) {
Thread thread=Thread.currentThread ();
System.out.printin (thread. activeCount ());
}
a. 0
b. true
c. 1
d. false
9. Which of the following is a correct constructor for a thread object?
a. Thread(Runnable a, String str);
b. Thread(Runnable a, int priority);
c. Thread(Runnable a, ThreadGroup t);
d. Thread(int priority);
10. Which of these keyword(s) is used to manually throw an exception?
a. try
b. finally
c. throw
d. catch
I wanted to take a moment to express my sincere appreciation for the incredible service and content your site provides. SAT Coaching in Hyderabad
ReplyDelete