-
What is the output of this program?
class newthread implements Runnable
{
Thread thread1,thread2;
newthread()
{
thread1 = new Thread(this,"Thread_1");
thread2 = new Thread(this,"Thread_2");
thread1.start();
thread2.start();
}
public void run()
{
thread2.setPriority(Thread.MAX_PRIORITY);
System.out.println(thread1.equals(thread2));
}
}
public class multithreaded_Example
{
public static void main(String args[])
{
new newthread();
}
}
-
- false
true - true
true - true
false - false
false - None of these
- false
Correct Option: D
Threads thread1 & thread2 are created by class newthread that is implementing runnable interface, hence both the threads are provided their own run() method specifying the actions to be taken. When constructor of newthread class is called first the run() method of thread1 executes than the run method of thread2 printing 2 times “false” as both the threads are not equal one is having different priority than other, hence false false is printed.