Menu
Topics Index
...
`

Output of Thread2358


If you need explanation Read this topic

If you need Answer Take test on this topic

Output of Thread2358
What will be the output of the following program?
public class OutputOfThread extends Thread {
    private OutputOfThread() {
        setPriority(NORM_PRIORITY);
        setPriority(MAX_PRIORITY);
        setPriority(MIN_PRIORITY);
    }
    public void run() {
        System.out.print("Run = ");
        System.out.println(Thread.currentThread().getPriority() + Thread.currentThread().getPriority());
    }
    public static void main(String[] args) {
        OutputOfThread oft = new OutputOfThread();
        System.out.print("Main = ");
        System.out.println(Thread.MAX_PRIORITY + Thread.MIN_PRIORITY + Thread.NORM_PRIORITY);
        oft.start();
    }
}

A. Main = 16
Run = 2
B. Main = 1015
Run = 11
C. Some other output
D. Output can not be determined
E. Compilation Error or Runtime Error
Topic: What is Multitasking and Multithreading?

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ANS is A
because min_priority=10,max= 1 and norm=5..(10+1+5=16)
and thread's priority is set to norm priority that is 1 (1+1=2)
so main=16
run=2

Posted by Mânïshå Mùlchåndânï    2014-07-15 12:50:48


Answer a.
main=16
max+min+norm priorities =10+1+5=16
run=2
getpriority givs 1
1+1=2

Posted by NagaRaj Nataraj    2014-07-15 12:54:56


Answer a.
max priority-10
min priority-1
norm priority-5
in main methd sop prints-
main= 10+1+5=16.
outputof thread contructor givs recently cald setpriority value wen getpriority() cald.
so min priority value 1 is priority value of currnt thtead
1+1=2.
run() methd prints
run=2.

Posted by Maheshwari Natarajan    2014-07-15 13:11:57


output cannot be determined........

Posted by Arul Palanisamy    2014-07-15 14:52:02


Congratulations Mânïshå Mùlchåndânï. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-07-16 05:35:43


© meritcampus 2019

All Rights Reserved.

Open In App