Question
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();
}
}
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();
}
}
Answer: Option D
Was this answer helpful ?
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 ?
Submit Solution