Java thread MCQ

Answer all questions carefully. After submission, you will see a detailed result and answer review.

Question 1
Which of the following constructor of class Thread is valid one?
Question 2
What is the output for the below code? <pre class="prettyprint"> class A implements Runnable{ public void run(){ System.out.println(Thread.currentThread().getName()); } } 1. public class Test{ 2. public static void main(String... args){ 3. A a = new A(); 4. Thread t = new Thread(a); 5. t.setName("good"); 6. t.start(); 7. } 8. } </pre>
Question 3
Predict the output: <pre class="prettyprint"> public class Test extends Thread{ private int i; public void run(){ i++; } public static void main(String[] args){ Test a = new Test(); a.run(); System.out.print(a.i); a.start(); System.out.print(a.i); } } </pre>
Question 4
What will be the output after compiling and executing the following code? <pre class="prettyprint"> public class Test implements Runnable{ public static void main(String[] args) throws InterruptedException{ Thread a = new Thread(new Test()); a.start(); System.out.print("Begin"); a.join(); System.out.print("End"); } public void run(){ System.out.print("Run"); } } </pre>
Question 5
What will be the output of the following program code? <pre class="prettyprint"> 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"); } } </pre>
Question 6
Given the code. What will be the result? <pre class="prettyprint"> public class Test implements Runnable{ public static void main(String[] args) throws InterruptedException{ Thread a = new Thread(new Test()); a.start(); System.out.print("Begin"); a.join(); System.out.print("End"); } public void run(){ System.out.print("Run"); } } </pre>
Question 7
What will be the output? <pre class="prettyprint"> 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(); } } </pre>
Question 8
What will happen when you attempt to compile and run the following code? <pre class="prettyprint"> 1. public class Test extends Thread{ 2. public static void main(String argv[]){ 3. Test t = new Test(); 4. t.run(); 5. t.start(); 6. } 7. public void run(){ 8. System.out.println("run-test"); 9. } 10. } </pre>
Question 9
Analyze the following code: <pre class="prettyprint"> 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"); } } </pre>
Question 10
Which of the following are methods of the Thread class? <p>1) yield()<br />2) sleep(long msec)<br />3) go()<br />4) stop()</p>