JAVA Threads 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. The program compiles fine. The program will not compile because it does not contain abstract methods. None of these The program will not compile because it does not implement the run() method. The program compiles fine. The program will not compile because it does not contain abstract methods. None of these ANSWER DOWNLOAD EXAMIANS APP
JAVA Threads 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(); }} Compilation succeed but Runtime Exception A A A A B B B B A B A B A B A B None of these Output order is not guaranteed Compilation succeed but Runtime Exception A A A A B B B B A B A B A B A B None of these Output order is not guaranteed ANSWER DOWNLOAD EXAMIANS APP
JAVA Threads 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); }} Prints Prints Compiler error IllegalThreadStateException is thrown Prints Prints Prints Compiler error IllegalThreadStateException is thrown Prints ANSWER DOWNLOAD EXAMIANS APP
JAVA Threads In java a thread can be created by .......... Extending the thread class. Both of the above Implementing Runnable interface. None of these Extending the thread class. Both of the above Implementing Runnable interface. None of these ANSWER DOWNLOAD EXAMIANS APP
JAVA Threads 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 Compilation succeed but Runtime Exception run-a run-a Compilation fails with an error at line 6 run-a None of these Compilation succeed but Runtime Exception run-a run-a Compilation fails with an error at line 6 run-a ANSWER DOWNLOAD EXAMIANS APP
JAVA Threads 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. } None of these true run-A true false run-A false false run-A true Compilation fails due to an error on line 7 None of these true run-A true false run-A false false run-A true Compilation fails due to an error on line 7 ANSWER DOWNLOAD EXAMIANS APP