JAVA Threads In java a thread can be created by .......... None of these 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. ANSWER DOWNLOAD EXAMIANS APP
JAVA Threads 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"); }} "BeginRunEnd" is printed. Compilation fails. "BeginEndRun" is printed. "BeginEnd" is printed. An exception is thrown at runtime. "BeginRunEnd" is printed. Compilation fails. "BeginEndRun" is printed. "BeginEnd" is printed. An exception is thrown at runtime. ANSWER DOWNLOAD EXAMIANS APP
JAVA Threads Which of the following constructor of class Thread is valid one? Thread(int priority) Thread(Runnable threadOb, String threadName) Thread(String threadName, int priority) Thread(Runnable threadOb, int priority) None of these Thread(int priority) Thread(Runnable threadOb, String threadName) Thread(String threadName, int priority) Thread(Runnable threadOb, int priority) None of these ANSWER DOWNLOAD EXAMIANS APP
JAVA Threads Which keyword when applied on a method indicates that only one thread should execute the method at a time. volatile synchronized native static final volatile synchronized native static final 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 IllegalThreadStateException is thrown Prints Compiler error Prints Prints IllegalThreadStateException is thrown Prints Compiler error Prints ANSWER DOWNLOAD EXAMIANS APP
JAVA Threads 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(); }} Compilation fails. "gogo" is printed An exception is thrown at runtime. "go" is printed "gogogo" is printed Compilation fails. "gogo" is printed An exception is thrown at runtime. "go" is printed "gogogo" is printed ANSWER DOWNLOAD EXAMIANS APP