Sail E0 Webinar
Question


What is the output of this program?


class newthread implements Runnable {
Thread t;
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();
}
}
Options:
A .  true
B .  false
C .  truetrue
D .  falsefalse
Answer: Option D

Threads t1 & t2 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 t1 executes 

than the run method of t2 printing 2 times “false” as both the threads are not equal one is

 having different priority than other, hence falsefalse is printed.
Output:
$ javac multithreaded_programing.java
$ java multithreaded_programing
falsefalse



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers