The following is a mock exam question:
public class
Test extends
Thread {
String msg = "default" ;
public Test(String s)
{
msg = s;
}
public void run()
{
System.out.println(msg);
}
public static void main(String args[])
{
new Test("String1").start();
new Test("String2").start();
System.out.println("end");
}
}
The explanation for this question is that there are three threads running in this program, main thread and two others. The order of thread execution is not guranteed. But when I compile and run this code snippet on Win98, the "end" always come before "String1" and "String2". Is this occur depending on the OS?
My question is whether the order of output is totally random or "end" always come before "String1" or "String2".
Thanks