Sail E0 Webinar

MCQs

Total Questions : 22 | Page 2 of 3 pages
Question 11. Predict the output:class A implements Runnable{ public void run(){ try{ for(int i=0;i
  1.    A B A B A B A B
  2.    Compilation succeed but Runtime Exception
  3.    A A A A B B B B
  4.    Output order is not guaranteed
  5.    None of these
 Discuss Question
Answer: Option C. -> A A A A B B B B
Question 12. What notifyAll() method do?
  1.    None of these
  2.    Wakes up one threads that are waiting on this object's monitor
  3.    Wakes up all threads that are waiting on this object's monitor
  4.    Wakes up all threads that are not waiting on this object's monitor
 Discuss Question
Answer: Option C. -> Wakes up all threads that are waiting on this object's monitor
Question 13. Which of the following are methods of the Thread class?1) yield()2) sleep(long msec)3) go()4) stop()
  1.    3 only
  2.    None of these
  3.    1 , 2 and 4
  4.    1 and 3
 Discuss Question
Answer: Option C. -> 1 , 2 and 4
Question 14. 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. }
  1.    None of these
  2.    false run-A false
  3.    true run-A true
  4.    false run-A true
  5.    Compilation fails due to an error on line 7
 Discuss Question
Answer: Option D. -> false run-A true
Question 15. What will be the output?class A extends Thread{ public void run(){ for(int i=0; i
  1.    0 0
  2.    Compilation succeed but runtime exception
  3.    0 1
  4.    Compilation error, class A has no start method
  5.    None of these
 Discuss Question
Answer: Option C. -> 0 1
Question 16. What is the output for the below code ?public class Test extends Thread{ public static void main(String argv[]){ Test t = new Test(); t.run(); } public void start(){ for(int i = 0; i < 10; i++){ System.out.println("Value of i = " + i); } }}
  1.    None of these
  2.    A run time error indicating that no run method is defined for the Thread class
  3.    Clean compile but no output at runtime
  4.    A compile time error indicating that no run method is defined for the Thread class
  5.    Clean compile and at run time the values 0 to 9 are printed out
 Discuss Question
Answer: Option C. -> Clean compile but no output at runtime
Question 17. Which keyword when applied on a method indicates that only one thread should execute the method at a time.
  1.    native
  2.    volatile
  3.    static
  4.    synchronized
  5.    final
 Discuss Question
Answer: Option D. -> synchronized
Question 18. 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); }}
  1.    IllegalThreadStateException is thrown
  2.    Prints
  3.    Prints
  4.    Compiler error
  5.    Prints
 Discuss Question
Answer: Option E. -> Prints
Question 19. 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"); }}
  1.    "BeginEndRun" is printed.
  2.    "BeginEnd" is printed.
  3.    Compilation fails.
  4.    An exception is thrown at runtime.
  5.    "BeginRunEnd" is printed.
 Discuss Question
Answer: Option E. -> "BeginRunEnd" is printed.
Question 20. What is the output for the below code ?class A implements Runnable{ public void run(){ System.out.println(Thread.currentThread().getName()); }}1. public class Test{2. public static void main(String... args){3. A a = new A();4. Thread t = new Thread(a);5. t.setName("good");6. t.start();7. }8. }
  1.    null
  2.    None of these
  3.    Compilation fails with an error at line 5
  4.    Compilation succeed but Runtime Exception
  5.    good
 Discuss Question
Answer: Option E. -> good

Latest Videos

Latest Test Papers