Lakshya Education MCQs

Question: What will be the output?
class A extends Thread{
public void run(){
for(int i=0; i
Options:
A.0 0
B.Compilation error, class A has no start method
C.0 1
D.Compilation succeed but runtime exception
E.None of these
Answer: Option C

Submit Answer & Explaination

Earn Reward Points by submitting Detailed Explaination for this Question

More Questions on This Topic :

Question 1. 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.    false run-A true
  2.    false run-A false
  3.    true run-A true
  4.    Compilation fails due to an error on line 7
  5.    None of these
Answer: Option A
Question 2. Which of the following are methods of the Thread class?
1) yield()
2) sleep(long msec)
3) go()
4) stop()
  1.    1 , 2 and 4
  2.    1 and 3
  3.    3 only
  4.    None of the above
Answer: Option A
Question 3. What notifyAll() method do?
  1.    Wakes up one threads that are waiting on this object's monitor
  2.    Wakes up all threads that are not waiting on this object's monitor
  3.    Wakes up all threads that are waiting on this object's monitor
  4.    None of the above
Answer: Option C
Question 4. Predict the output:
class A implements Runnable{
public void run(){
try{
for(int i=0;i
  1.    A A A A B B B B
  2.    A B A B A B A B
  3.    Output order is not guaranteed
  4.    Compilation succeed but Runtime Exception
  5.    None of these
Answer: Option A
Question 5. 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.    run-a
  2.    run-a run-a
  3.    Compilation fails with an error at line 6
  4.    Compilation succeed but Runtime Exception
  5.    None of these
Answer: Option D
Question 6. 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 run-test
  2.    run-test
  3.    Compilation fails due to an error on line 4
  4.    Compilation fails due to an error on line 7
  5.    None of these
Answer: Option A

Check all Questions in this Topic : Click HERE