我一直在为我的 O/SCJP 考试做一些练习。考虑以下代码:
public class Cruiser implements Runnable {
public static void main(String[] args) throws InterruptedException {
Thread a = new Thread(new Cruiser());
a.start();
System.out.print("Begin");
a.join();
System.out.print("End");
}
public void run() {
System.out.print("Run");
}
}
来源:http ://scjptest.com/mock-test.xhtml
该站点声明输出(他们模拟问题的答案)将是BeginRunEnd
,并且在正常运行课程时,这正是输出的内容。
但是,调试时输出为RunBeginEnd
.
公平地说,在正常执行下,输出将始终是BeginRunEnd
或者这会根据其他因素而变化(例如新线程类的重量/启动线程后加入它需要多长时间)?
你会说这是一个公平/准确的考试问题吗?