Threads

Q1: 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(); 
    } 
}

A The code fails to compile in the main() method

B
The code fails to compile in the run() method

C Only the text "In run" will be displayed

D The text "In run" followed by "Leaving run" will be displayed

ANS:A - The code fails to compile in the main() method

yield() allow other Threads to execute by stopping the current Thread. Since there are no such other Threads present, therefore yield() not blocks the current Thread and execution continues after yield().  



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.