Q.1.
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"); } }
Q.2.
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(); } }
Q.3.
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"); } }
Q.4.
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); } }
Q.5.
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();}}
Q.6.
Which keyword when applied on a method indicates that only one thread should execute the method at a time.
Q.7.
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 =i <i++){ System.out.println("Value of i = " + i); } } }
Q.8.
What notifyAll() method do?
Q.9.
Which of the following are methods of the Thread class?yield()sleep(long msec)go()stop()
Q.10.
What will be the output? class A extends Thread{ public void run(){ for(int i=i
Q.11.
Predict the output: class A implements Runnable{ public void run(){ try{ for(int i=0;i
Q.12.
What will be the output? class One extends Thread{ public void run(){ for(int i=i
Q.13.
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();}}
Q.14.
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");}}
Q.15.
Analyze the following code: public class Test implements Runnable{ public static void main(String[] args){ Test t = new Test(); t.start(); } public void run() { } }
Q.16.
Analyze the following code: public abstract class Test implements Runnable{ public void doSomething() { }; }
Q.17.
Which of the following constructor of class Thread is valid one?
Q.18.
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"); } }
Q.19.
When a class extends the Thread class ,it should override ............ method of Thread class to start that thread.
Q.20.
In java a thread can be created by ..........