Menu
Topics Index
...
`

My Thread Name


If you need explanation Read this topic

If you need Answer Take test on this topic

My Thread Name
What will be the output of the following program?
public class Worker extends Thread {
    Worker() {
        setName("Ashok");
        setPriority(Thread.MIN_PRIORITY);
    }
    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.run();
        Worker w1 = new Worker();
        w1.start();
    }
}

A. main~5~Ashok~1~
B. main~5~Ashok~0~
C. main~5~main~0~
D. main~1~main~5~
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.

Ans:A First w.run(); is a normal call which will be executed by main.hence o/p:(main~5~) then ashok~1~(min priority is 1)

Posted by Indrasena Reddy    2014-05-15 09:18:13


ans is A bcz first  w.run() is a normal call which will be executed by main and hence we get 1st (main~5~) worker1's w1 object is created and ashok ,minpriority are set as name and priority of thread respectively then  ashok~1~ is printed by printThreadDetails

Posted by Pooja Singh    2014-05-15 09:57:58


F is the answer

Posted by Ramesh Karlagunta    2014-05-15 10:28:59


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

Posted by Merit Campus    2014-05-16 04:26:27


© meritcampus 2019

All Rights Reserved.

Open In App