Which of the following constructor of class Thread is valid one? None of these Thread(int priority) Thread(Runnable threadOb, int priority) Thread(Runnable threadOb, String threadName) Thread(String threadName, int priority) TRUE ANSWER : ? YOUR ANSWER : ?
Analyze the following code:public abstract class Test implements Runnable{ public void doSomething() { };} None of these The program compiles fine. The program will not compile because it does not contain abstract methods. The program will not compile because it does not implement the run() method. TRUE ANSWER : ? YOUR ANSWER : ?
Analyze the following code:public class Test implements Runnable{ public static void main(String[] args){ Test t = new Test(); t.start(); } public void run() { }} The program compiles, but it does not run because the run() method is not implemented. The program compiles, but it does not run because the start() method is not defined. The program compiles and runs fine. The program does not compile because the start() method is not defined in the Test class. 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 0 1 Compilation Error None of these 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. } run-a run-a Compilation succeed but Runtime Exception Compilation fails with an error at line 6 run-a 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. } false run-A true false run-A false None of these Compilation fails due to an error on line 7 true run-A true 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 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. The program compiles and runs and displays test. 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 : ?
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(); }} Compilation error, class A has no start method Compilation succeed but runtime exception 0 1 0 0 None of these 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(); }} "gogogo" is printed "gogo" is printed An exception is thrown at runtime. "go" is printed Compilation fails. TRUE ANSWER : ? YOUR ANSWER : ?