Java Programming - Threads - Discussion

Discussion Forum : Threads - Finding the output (Q.No. 15)
15.
What will be the output of the program?
public class ThreadTest extends Thread 
{ 
    public void run() 
    { 
        System.out.println("In run"); 
        yield(); 
        System.out.println("Leaving run"); 
    } 
    public static void main(String []argv) 
    { 
        (new ThreadTest()).start(); 
    } 
}
The code fails to compile in the main() method
The code fails to compile in the run() method
Only the text "In run" will be displayed
The text "In run" followed by "Leaving run" will be displayed
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
13 comments Page 2 of 2.

Smith said:   1 decade ago
What is output for this program ?

Like
"In run
Leaving run"
or
like
"In run Leaving run"

Sudhansu said:   1 decade ago
yield() is a static method . Thes how we are invoking it for an instance using this.

Manish said:   1 decade ago
Yield is a static method. It makes the currently running thread head back to the runnable state to allow other threads of same priority to get their turn, but there is no such guarantee.


Post your comments here:

Your comments will be displayed after verification.