我有2個問題: 1.爲什麼運行程序時不會調用run() 2.如果調用run(),它是否會更改randomScore的值?爲什麼run方法不被調用?
import java.*;
public class StudentThread extends Thread {
int ID;
public static volatile int randomScore; //will it change the value of randomScore defined here?
StudentThread(int i) {
ID = i;
}
public void run() {
randomScore = (int)(Math.random()*1000);
}
public static void main(String args[]) throws Exception {
for (int i = 1;i< 10 ;i++)
{
StudentThread student = new StudentThread(5);
student.start();
System.out.println(randomScore);
}
}
}
abt問題1如何? – John
已更新的答案。 – aioobe
我只是再添加1個問題。你可以幫我嗎? – John