MCQs
Total Questions : 86
| Page 2 of 9 pages
Answer: Option A. -> A A A A B B B B
Answer: Option C. -> 0 1
Question 13. 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. }
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. }
Answer: Option A. -> false run-A true
Answer: Option A. -> 1 , 2 and 4
Answer: Option C. -> Wakes up all threads that are waiting on this object's monitor
Answer: Option D. -> Clean compile but no output at runtime
Answer: Option B. -> synchronized
Question 18. 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. }
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. }
Answer: Option A. -> good
Answer: Option C. -> Prints
Question 20. 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");
}
}
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");
}
}
Answer: Option C. -> "BeginRunEnd" is printed.