Question 1 of 25
Hints left: 3
Q1
What will be output of the following program code? public class Test implements Runnable{ public void run(){ System.out.print("go"); } public static void main(String arg[]) { Thread t = new Thread(new Test()); t.run(); t.run(); t.start(); } }
Q2
What will be the output? class A extends Thread{ public void run(){ for(int i=0; i<2; i++){ System.out.println(i); } } } public class Test{ public static void main(String argv[]){ Test t = new Test(); t.check(new A(){}); } public void check(A a){ a.start(); } }
Q3
Analyze the following code: public abstract class Test implements Runnable{ public void doSomething() { }; }
Q4
What will be the output of the following Java code? class newthread extends Thread { Thread t; newthread() { t = new Thread(this,"New Thread"); t.start(); } public void run() { System.out.println(t.isAlive()); } } class multithreaded_programing { public static void main(String args[]) { new newthread(); } }
Q5
What will be the output after compiling and executing the following code? 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"); } }
Q6
What is the output for the below code? public class Test extends Thread{ public static void main(String argv[]){ Test t = new Test(); t.run(); } public void start(){ for(int i = 0; i < 10; i++){ System.out.println("Value of i = " + i); } } }
Q7
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"); } }
Q8
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(); } }
Q9
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(); } }
Q10
Analyze the following code: public class Test implements Runnable{ public static void main(String[] args){ Test t = new Test(); t.start(); } public void run() { } }
Q11
Given the code. What will be the result? 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"); } }
Q12
What is the output for the below code? class A implements Runnable{ public void run(){ System.out.println(Thread.currentThread().getName()); } } public class Test{ public static void main(String... args){ A a = new A(); Thread t = new Thread(a); t.setName("good"); t.start(); } }
Q13
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"); } }
Q14
What will be the output of the following Java code? class newthread implements Runnable { Thread t; newthread() { t = new Thread(this,"My Thread"); t.start(); } public void run() { System.out.println(t); } } class multithreaded_programing { public static void main(String args[]) { new newthread(); } }
Q15
Which of the following are methods of the Thread class? 1) yield() 2) sleep(long msec) 3) go() 4) stop()
Q16
What is true about threading?
Q17
What will be the output of the following Java code? class newthread implements Runnable { Thread t; newthread() { t = new Thread(this,"My Thread"); t.start(); } } class multithreaded_programing { public static void main(String args[]) { new newthread(); } }
Q18
What will be the output of the following Java program? class newthread extends Thread { Thread t; String name; newthread(String threadname) { name = threadname; t = new Thread(this,name); t.start(); } public void run() { } } class multithreaded_programing { public static void main(String args[]) { newthread obj1 = new newthread("one"); newthread obj2 = new newthread("two"); try { obj1.t.wait(); System.out.print(obj1.t.isAlive()); } catch(Exception e) { System.out.print("Main thread interrupted"); } } }
Q19
Predict the output: 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); } }
Q20
What will happen when you attempt to compile and run the following code? class A implements Runnable{ public void run(){ System.out.println("run-A"); } } public class Test{ public static void main(String argv[]){ A a = new A(); Thread t = new Thread(a); System.out.println(t.isAlive()); t.start(); System.out.println(t.isAlive()); } }
Q21
Predict the output: class A implements Runnable{ public void run(){ try{ for(int i=0;i<4;i++){ Thread.sleep(100); System.out.println(Thread.currentThread().getName()); } }catch(InterruptedException e){ } } } public class Test{ public static void main(String argv[]) throws Exception{ A a = new A(); Thread t = new Thread(a, "A"); Thread t1 = new Thread(a, "B"); t.start(); t.join(); t1.start(); } }
Q22
What will be the output of the following Java code? class newthread extends Thread { Thread t1,t2; newthread() { t1 = new Thread(this,"Thread_1"); t2 = new Thread(this,"Thread_2"); t1.start(); t2.start(); } public void run() { t2.setPriority(Thread.MAX_PRIORITY); System.out.print(t1.equals(t2)); } } class multithreaded_programing { public static void main(String args[]) { new newthread(); } }
Q23
What notifyAll() method do?
Q24
Which keyword when applied on a method indicates that only one thread should execute the method at a time.
Q25
Which of this method is used to avoid polling in Java?