Sail E0 Webinar
Question


What is the output of this program?


class newthread implements Runnable {
Thread t;
newthread() {
t = new Thread(this,"New Thread");
t.start();
}
public void run() {
t.setPriority(Thread.MAX_PRIORITY);
System.out.println(t);
}
}
class multithreaded_programing {
public static void main(String args[]) {
new newthread();
}
}
Options:
A .  Thread[New Thread,0,main]
B .  Thread[New Thread,1,main]
C .  Thread[New Thread,5,main]
D .  Thread[New Thread,10,main]
Answer: Option D

Thread t has been made with default priority value 5 but in run method the priority has 

been explicitly changed to MAX_PRIORITY of class thread, that is 10 by code 't.setPriority(Thread.MAX_PRIORITY);' using the setPriority function of thread t.
Output:
$ javac multithreaded_programing.java
$ java multithreaded_programing
Thread[New Thread,10,main]



Was this answer helpful ?
Next Question

Submit Solution

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

Latest Videos

Latest Test Papers