Question 35 (Java)

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?

[advanced_iframe securitykey=”undefined” src=”https://ide.kodnest.com/?tgp0″ width=”100%” height=”600″]

×