我有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