JAVA Threads When a class extends the Thread class ,it should override ............ method of Thread class to start that thread. go() start() run() init() go() start() run() init() ANSWER DOWNLOAD EXAMIANS APP
JAVA Threads 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"); }} "BeginEndRun" is printed. An exception is thrown at runtime. "BeginEnd" is printed. Compilation fails. "BeginRunEnd" is printed. "BeginEndRun" is printed. An exception is thrown at runtime. "BeginEnd" is printed. Compilation fails. "BeginRunEnd" is printed. ANSWER DOWNLOAD EXAMIANS APP
JAVA Threads 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 has a compilation error because t is defined in both the main() method and the constructor Test(). The program compiles and runs and displays nothing. The program compiles and runs and displays test. The program compiles fine, but it does not run because you cannot use the keyword this in the constructor. The program has a compilation error because t is defined in both the main() method and the constructor Test(). The program compiles and runs and displays nothing. The program compiles and runs and displays test. The program compiles fine, but it does not run because you cannot use the keyword this in the constructor. ANSWER DOWNLOAD EXAMIANS APP
JAVA Threads Which of the following are methods of the Thread class?1) yield()2) sleep(long msec)3) go()4) stop() None of these 1 and 3 1 , 2 and 4 3 only None of these 1 and 3 1 , 2 and 4 3 only ANSWER DOWNLOAD EXAMIANS APP
JAVA Threads 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 Compilation succeed but runtime exception 0 1 0 0 Compilation error, class A has no start method None of these Compilation succeed but runtime exception 0 1 0 0 Compilation error, class A has no start method 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