Vidyalelo
Java Programming · all questions

Threads
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

105

Questions

2/6

Page

Pick an option on a question to see the right answer and solution.

What is the purpose of the isDaemon() method in Java threads?

Select an option to see the answer and solution.

In Java, what happens when a thread encounters an uncaught exception and terminates abruptly?

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?

Select an option to see the answer and solution.

In Java, what is the purpose of the isInterrupted() method in threads?

Select an option to see the answer and solution.

How can you handle exceptions in Java threads?

Select an option to see the answer and solution.

In Java, which class is used to create and manage thread groups?

Select an option to see the answer and solution.

What is the purpose of the setPriority() method in Java threads?

Select an option to see the answer and solution.

In Java, can you directly access the run() method of a Thread object?

Select an option to see the answer and solution.

What is the purpose of the getState() method in Java threads?

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 ..........

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.

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");
        }
}

Select an option to see the answer and solution.

Which of the following constructor of class Thread is valid one?

Select an option to see the answer and solution.

Analyze the following code:
public abstract class Test implements Runnable{
        public void doSomething() { };
}

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() { }
}

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");
        }
}

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();
	}
}

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");
      }
}

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();
      }
}

Select an option to see the answer and solution.