Sail E0 Webinar

MCQs

Total Questions : 22 | Page 1 of 3 pages
Question 1. In java a thread can be created by ..........
  1.    Both of the above
  2.    Extending the thread class.
  3.    None of these
  4.    Implementing Runnable interface.
 Discuss Question
Answer: Option A. -> Both of the above
Question 2. Which of the following constructor of class Thread is valid one?
  1.    Thread(Runnable threadOb, String threadName)
  2.    Thread(Runnable threadOb, int priority)
  3.    None of these
  4.    Thread(int priority)
  5.    Thread(String threadName, int priority)
 Discuss Question
Answer: Option A. -> Thread(Runnable threadOb, String threadName)
Question 3. When a class extends the Thread class ,it should override ............ method of Thread class to start that thread.
  1.    run()
  2.    start()
  3.    init()
  4.    go()
 Discuss Question
Answer: Option A. -> run()
Question 4. What will be the output of the following program code?public class Test implements Runnable{ public static void main(String[] args){ Thread t = new Thread(this); t.start(); } public void run(){ System.out.println("test"); }}
  1.    The program compiles and runs fine and displays test on the console.
  2.    The program does not compile because this cannot be referenced in a static method.
  3.    The program compiles fine, but it does not print anything because t does not invoke the run() method
  4.    None of these
 Discuss Question
Answer: Option B. -> The program does not compile because this cannot be referenced in a static method.
Question 5. Analyze the following code:public abstract class Test implements Runnable{ public void doSomething() { };}
  1.    None of these
  2.    The program compiles fine.
  3.    The program will not compile because it does not contain abstract methods.
  4.    The program will not compile because it does not implement the run() method.
 Discuss Question
Answer: Option B. -> The program compiles fine.
Question 6. Analyze the following code:public class Test implements Runnable{ public static void main(String[] args){ Test t = new Test(); t.start(); } public void run() { }}
  1.    The program does not compile because the start() method is not defined in the Test class.
  2.    The program compiles, but it does not run because the run() method is not implemented.
  3.    The program compiles, but it does not run because the start() method is not defined.
  4.    The program compiles and runs fine.
 Discuss Question
Answer: Option A. -> The program does not compile because the start() method is not defined in the Test class.
Question 7. What will be the output?class One extends Thread{public void run(){for(int i=0; i
  1.    0 0
  2.    None of these
  3.    0 1
  4.    Compilation Error
 Discuss Question
Answer: Option C. -> 0 1
Question 8. What will happen when you attempt to compile and run the following code?1. public class Test extends Thread{2. public static void main(String argv[]){3. Test t = new Test();4. t.run();5. t.start();6. }7. public void run(){8. System.out.println("run-test");9. }10. }
  1.    run-test
  2.    None of these
  3.    Compilation fails due to an error on line 4
  4.    Compilation fails due to an error on line 7
  5.    run-test run-test
 Discuss Question
Answer: Option E. -> run-test run-test
Question 9. 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. }
  1.    Compilation succeed but Runtime Exception
  2.    Compilation fails with an error at line 6
  3.    run-a run-a
  4.    None of these
  5.    run-a
 Discuss Question
Answer: Option A. -> Compilation succeed but Runtime Exception
Question 10. 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"); }}
  1.    The program compiles and runs and displays test.
  2.    The program compiles fine, but it does not run because you cannot use the keyword this in the constructor.
  3.    The program compiles and runs and displays nothing.
  4.    The program has a compilation error because t is defined in both the main() method and the constructor Test().
 Discuss Question
Answer: Option A. -> The program compiles and runs and displays test.

Latest Videos

Latest Test Papers