51. 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();
}
}
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();
}
}
52. 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");
}
}
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");
}
}
53. Which of this method is used to avoid polling in Java?
54. What will be the output of the following Java code?
class newthread implements Runnable
{
Thread t;
newthread()
{
t = new Thread(this,"My Thread");
t.start();
}
public void run()
{
System.out.println(t);
}
}
class multithreaded_programing
{
public static void main(String args[])
{
new newthread();
}
}
class newthread implements Runnable
{
Thread t;
newthread()
{
t = new Thread(this,"My Thread");
t.start();
}
public void run()
{
System.out.println(t);
}
}
class multithreaded_programing
{
public static void main(String args[])
{
new newthread();
}
}
55. What will be the output of the following Java code?
class newthread extends Thread
{
Thread t;
newthread()
{
t = new Thread(this,"New Thread");
t.start();
}
public void run()
{
System.out.println(t.isAlive());
}
}
class multithreaded_programing
{
public static void main(String args[])
{
new newthread();
}
}
class newthread extends Thread
{
Thread t;
newthread()
{
t = new Thread(this,"New Thread");
t.start();
}
public void run()
{
System.out.println(t.isAlive());
}
}
class multithreaded_programing
{
public static void main(String args[])
{
new newthread();
}
}
56. What will be the output of the following Java code?
class newthread extends Thread
{
Thread t1,t2;
newthread()
{
t1 = new Thread(this,"Thread_1");
t2 = new Thread(this,"Thread_2");
t1.start();
t2.start();
}
public void run()
{
t2.setPriority(Thread.MAX_PRIORITY);
System.out.print(t1.equals(t2));
}
}
class multithreaded_programing
{
public static void main(String args[])
{
new newthread();
}
}
class newthread extends Thread
{
Thread t1,t2;
newthread()
{
t1 = new Thread(this,"Thread_1");
t2 = new Thread(this,"Thread_2");
t1.start();
t2.start();
}
public void run()
{
t2.setPriority(Thread.MAX_PRIORITY);
System.out.print(t1.equals(t2));
}
}
class multithreaded_programing
{
public static void main(String args[])
{
new newthread();
}
}
57. What is true about threading?
58. What will be the output of the following Java program?
class newthread extends Thread
{
Thread t;
String name;
newthread(String threadname)
{
name = threadname;
t = new Thread(this,name);
t.start();
}
public void run()
{
}
}
class multithreaded_programing
{
public static void main(String args[])
{
newthread obj1 = new newthread("one");
newthread obj2 = new newthread("two");
try
{
obj1.t.wait();
System.out.print(obj1.t.isAlive());
}
catch(Exception e)
{
System.out.print("Main thread interrupted");
}
}
}
class newthread extends Thread
{
Thread t;
String name;
newthread(String threadname)
{
name = threadname;
t = new Thread(this,name);
t.start();
}
public void run()
{
}
}
class multithreaded_programing
{
public static void main(String args[])
{
newthread obj1 = new newthread("one");
newthread obj2 = new newthread("two");
try
{
obj1.t.wait();
System.out.print(obj1.t.isAlive());
}
catch(Exception e)
{
System.out.print("Main thread interrupted");
}
}
}
59. What will be the output of the following Java code?
class newthread implements Runnable
{
Thread t;
newthread()
{
t = new Thread(this,"My Thread");
t.start();
}
}
class multithreaded_programing
{
public static void main(String args[])
{
new newthread();
}
}
class newthread implements Runnable
{
Thread t;
newthread()
{
t = new Thread(this,"My Thread");
t.start();
}
}
class multithreaded_programing
{
public static void main(String args[])
{
new newthread();
}
}
60. What will be the output of the following Java code?
class newthread implements Runnable
{
Thread t;
newthread()
{
t = new Thread(this,"My Thread");
t.start();
}
public void run()
{
System.out.println(t.getName());
}
}
class multithreaded_programing
{
public static void main(String args[])
{
new newthread();
}
}
class newthread implements Runnable
{
Thread t;
newthread()
{
t = new Thread(this,"My Thread");
t.start();
}
public void run()
{
System.out.println(t.getName());
}
}
class multithreaded_programing
{
public static void main(String args[])
{
new newthread();
}
}
Read More Section(Threads)
Each Section contains maximum 100 MCQs question on Threads. To get more questions visit other sections.