Which keyword when applied on a method indicates that only one thread should execute the method at a time. synchronized volatile native final static TRUE ANSWER : ? YOUR ANSWER : ?
What notifyAll() method do? None of these 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 Wakes up all threads that are waiting on this object's monitor TRUE ANSWER : ? YOUR ANSWER : ?
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(); }} Output order is not guaranteed None of these Compilation succeed but Runtime Exception A B A B A B A B A A A A B B B B 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. } None of these run-a run-a Compilation fails with an error at line 6 Compilation succeed but Runtime Exception run-a TRUE ANSWER : ? YOUR ANSWER : ?
What will happen when you attempt to compile and run the following code?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. } None of these Compilation fails due to an error on line 7 Compilation fails due to an error on line 4 run-test run-test run-test TRUE ANSWER : ? YOUR ANSWER : ?
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(); }} An exception is thrown at runtime. "gogo" is printed "go" is printed "gogogo" is printed Compilation fails. TRUE ANSWER : ? YOUR ANSWER : ?
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(); }} None of these 0 1 Compilation succeed but runtime exception 0 0 Compilation error, class A has no start method TRUE ANSWER : ? YOUR ANSWER : ?
Analyze the following code:public abstract class Test implements Runnable{ public void doSomething() { };} The program will not compile because it does not implement the run() method. None of these The program will not compile because it does not contain abstract methods. The program compiles fine. TRUE ANSWER : ? YOUR ANSWER : ?
In java a thread can be created by .......... Extending the thread class. None of these Implementing Runnable interface. Both of the above TRUE ANSWER : ? YOUR ANSWER : ?
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"); }} An exception is thrown at runtime. "BeginEndRun" is printed. "BeginRunEnd" is printed. Compilation fails. "BeginEnd" is printed. TRUE ANSWER : ? YOUR ANSWER : ?