Menu
Topics Index
...
`

Worker Name2361


If you need explanation Read this topic

If you need Answer Take test on this topic

Worker Name2361
What will be the output of the following program?
public class Worker extends Thread {
    Worker() {
        setName("Ashok");
        setPriority(Thread.MAX_PRIORITY);
    }
    public void start() {
        printThreadDetails(Thread.currentThread());
    }
    public void run() {
        printThreadDetails(Thread.currentThread());
    }
    public void printThreadDetails(Thread t) {
        System.out.print(t.getName() + "~" + t.getPriority() + "~");
    }
    public static void main(String[] args) {
        Worker w = new Worker();
        w.start();
        Worker w1 = new Worker();
        w1.run();
    }
}

A. Ashok~10~Ashok~10~
B. Ashok~10~main~5~
C. main~5~Ashok~10~
D. Some other output
E. Output can not be determined
F. 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.

D. some other output such as main~5 main~5 bcz. since no name is asigned main is taken default name and priority is 5 .

Posted by Shabaaz Shaikz    2014-01-08 12:45:13


Ans is D... main method is in execution...in main start method is invoked with the class object...here main is the thread...the current thread is MAIN and its priority is 5....similarly for 2nd obj main will be the thread and its priority is 5...

Posted by Santosh Munugota    2014-01-08 12:50:11


Ans is d because here main() method is in execution n default priority is 5 so out put wil be main~5~main~5~

Posted by Uday Kumar    2014-01-08 15:36:43


Congratulations Shabaaz Shaikz. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-01-09 04:09:09


tnkq> :-)

Posted by Shabaaz Shaikz    2014-01-09 04:22:44


© meritcampus 2019

All Rights Reserved.

Open In App