• public class MyClass {…

  • Akash 

    Administrator
    at

    public class MyClass {

    public static int num=1;

    public static boolean flag=false;

    public static void main(String[] args) {

    Thread t =new Thread(new MyThread());

    t.start();

    MyClass.flag=true;

    MyClass.num=10;

    }

    }

    class MyThread implements Runnable{

    public void run() {

    while(!MyClass.flag){

    Thread.yield();

    }

    System.out.println(MyClass.num);

    }

    }

    Output of this code and the reason for the output?

Log in to reply.

Original Post
0 of 0 posts June 2018
Now
KodNest Training New Batch is starting on 21st September 2020. Attend one week free demo classes.Register Now

New Report

Close