What is the purpose of the isDaemon() method in Java threads?
A. It checks if a thread is currently running
B. It checks if a thread is sleeping
C. It checks if a thread is a daemon thread
D. It checks if a thread is waiting
Select an option to see the answer and solution.
In Java, what happens when a thread encounters an uncaught exception and terminates abruptly?
A. The thread is paused indefinitely
B. The JVM prints the exception trace and terminates the thread
C. The thread resumes execution without any impact
D. None of These
Select an option to see the answer and solution.
What is the result of calling the setDaemon(true) method on a running thread in Java?
A. It resumes the thread
B. It pauses the thread
C. It sets the thread as a daemon thread
D. It stops the thread immediately
Select an option to see the answer and solution.
In Java, what is the purpose of the isInterrupted() method in threads?
A. It checks if a thread is a daemon thread
B. It checks if a thread is waiting
C. It checks if a thread is running
D. It checks if a thread has been interrupted
Select an option to see the answer and solution.
How can you handle exceptions in Java threads?
A. By using try-catch blocks within the run() method
B. By using the stop() method
C. By ignoring exceptions in threads
D. By using the yield() method
Select an option to see the answer and solution.
In Java, which class is used to create and manage thread groups?
A. GroupManager
B. ThreadController
C. ThreadManager
D. ThreadGroup
Select an option to see the answer and solution.
What is the purpose of the setPriority() method in Java threads?
A. It starts a new thread
B. It resumes a paused thread
C. It sets the priority of a thread
D. It synchronizes threads
Select an option to see the answer and solution.
In Java, can you directly access the run() method of a Thread object?
A. Only if the thread is marked as "final"
B. Yes, but it will execute in the current thread, not as a separate thread
C. Only if the thread is marked as "static"
D. None of These
Select an option to see the answer and solution.
What is the purpose of the getState() method in Java threads?
A. It suspends a thread
B. It starts a new thread
C. It retrieves the current state of a thread
D. It sets the state of a thread
Select an option to see the answer and solution.
In Java, what is the maximum thread priority value?
Select an option to see the answer and solution.
In java a thread can be created by ..........
A. Extending the thread class.
B. Implementing Runnable interface.
C. Both of the above
D. None of these
Select an option to see the answer and solution.
When a class extends the Thread class ,it should override ............ method of Thread class to start that thread.
A. start()
B. run()
C. init()
D. go()
Select an option to see the answer and solution.
What will be the output of the following program code?
public class Test implements Runnable{
public static void main(String[] args){
Thread t = new Thread(this);
t.start();
}
public void run(){
System.out.println("test");
}
}A. The program does not compile because this cannot be referenced in a static method.
B. The program compiles fine, but it does not print anything because t does not invoke the run() method
C. The program compiles and runs fine and displays test on the console.
D. None of the above
Select an option to see the answer and solution.
Which of the following constructor of class Thread is valid one?
A. Thread(Runnable threadOb, int priority)
B. Thread(int priority)
C. Thread(Runnable threadOb, String threadName)
D. Thread(String threadName, int priority)
E. None of these
Select an option to see the answer and solution.
Analyze the following code:
public abstract class Test implements Runnable{
public void doSomething() { };
}A. The program will not compile because it does not implement the run() method.
B. The program will not compile because it does not contain abstract methods.
C. The program compiles fine.
D. None of the above
Select an option to see the answer and solution.
Analyze the following code:
public class Test implements Runnable{
public static void main(String[] args){
Test t = new Test();
t.start();
}
public void run() { }
}A. The program does not compile because the start() method is not defined in the Test class.
B. The program compiles, but it does not run because the start() method is not defined.
C. The program compiles, but it does not run because the run() method is not implemented.
D. The program compiles and runs fine.
Select an option to see the answer and solution.
Analyze the following code:
public class Test implements Runnable{
public static void main(String[] args){
Test t = new Test();
}
public Test(){
Thread t = new Thread(this);
t.start();
}
public void run(){
System.out.println("test");
}
}A. The program has a compilation error because t is defined in both the main() method and the constructor Test().
B. The program compiles fine, but it does not run because you cannot use the keyword this in the constructor.
C. The program compiles and runs and displays nothing.
D. The program compiles and runs and displays test.
Select an option to see the answer and solution.
What will be the output?
class One extends Thread{
public void run(){
for(int i=0; i<2; i++){
System.out.print(i);
}
}
}
public class Test{
public static void main(String args[]){
Test t = new Test();
t.call(new One());
}
public void call(One o){
o.start();
}
}A. 0 0
B. Compilation Error
C. 0 1
D. None of these
Select an option to see the answer and solution.
What will happen when you attempt to compile and run the following code?
public class Test extends Thread{
public static void main(String argv[]){
Test t = new Test();
t.run();
t.start();
}
public void run(){
System.out.println("run-test");
}
}A. run-test run-test
B. run-test
C. Compilation fails due to an error on line 4
D. Compilation fails due to an error on line 7
E. None of these
Select an option to see the answer and solution.
What will happen after compiling and running following code?
class A implements Runnable{
public void run(){
System.out.println("run-a");
}
}
public class Test{
public static void main(String... args){
A a = new A();
Thread t = new Thread(a);
t.start();
t.start();
}
}A. run-a
B. run-a run-a
C. Compilation fails with an error at line 6
D. Compilation succeed but Runtime Exception
E. None of these
Select an option to see the answer and solution.