In java a thread can be created by .......... Both of the above None of these Implementing Runnable interface. Extending the thread class. TRUE ANSWER : ? YOUR ANSWER : ?
Analyze the following code:public abstract class Test implements Runnable{ public void doSomething() { };} None of these The program will not compile because it does not contain abstract methods. The program compiles fine. The program will not compile because it does not implement the run() method. TRUE ANSWER : ? YOUR ANSWER : ?
When a class extends the Thread class ,it should override ............ method of Thread class to start that thread. init() go() run() start() TRUE ANSWER : ? YOUR ANSWER : ?
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"); }} The program compiles and runs and displays test. The program compiles and runs and displays nothing. The program has a compilation error because t is defined in both the main() method and the constructor Test(). The program compiles fine, but it does not run because you cannot use the keyword this in the constructor. TRUE ANSWER : ? YOUR ANSWER : ?
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();}} 0 0 None of these 0 1 Compilation Error TRUE ANSWER : ? YOUR ANSWER : ?
What will happen after compiling and running following code?class A implements Runnable{ public void run(){ System.out.println("run-a"); }}1. public class Test{2. public static void main(String... args){3. A a = new A();4. Thread t = new Thread(a);5. t.start();6. t.start();7. }8. } Compilation fails with an error at line 6 run-a Compilation succeed but Runtime Exception None of these run-a run-a TRUE ANSWER : ? YOUR ANSWER : ?
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"); }} The program compiles fine, but it does not print anything because t does not invoke the run() method The program does not compile because this cannot be referenced in a static method. The program compiles and runs fine and displays test on the console. None of these TRUE ANSWER : ? YOUR ANSWER : ?
What notifyAll() method do? Wakes up all threads that are waiting on this object's monitor Wakes up one threads that are waiting on this object's monitor Wakes up all threads that are not waiting on this object's monitor None of these TRUE ANSWER : ? YOUR ANSWER : ?
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"); }}1. public class Test{2. public static void main(String argv[]){3. A a = new A();4. Thread t = new Thread(a);5. System.out.println(t.isAlive());6. t.start();7. System.out.println(t.isAlive());8. }9. } Compilation fails due to an error on line 7 true run-A true false run-A false None of these false run-A true TRUE ANSWER : ? YOUR ANSWER : ?
Which keyword when applied on a method indicates that only one thread should execute the method at a time. final synchronized native volatile static TRUE ANSWER : ? YOUR ANSWER : ?