Sail E0 Webinar
Question


What is the output of this program?


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();
}
}
Options:
A .  true
B .  false
C .  truetrue
D .  falsefalse
Answer: Option D

This program was previously done by using  Runnable interface, here we  have used 

Thread class. This shows both the method are equivalent, we can use any of them to 

create a thread.

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