class MyThread extends Thread
{
public void run()
{
for(int i=0; i<10; i++)
{
System.out.println("child thread");
Thread.yield();
/* we comment this line, then both threads will
execute simultaneously and
we can't expect which thread will
complete first.
if we not comment then main thread
will get the more chance.
*/
}
}
}
class Yield
{
public static void main(String args[])
{
Thread t=new Thread();
t.start();
for(int i=0; i<10;i++)
{
System.out.println("This is main
Thread");
}
}
}output: