是新的多线程编程,当我宣布run()
方法为静态的给编译器错误的为什么不能在多线程中使用run()方法?
“这种静态方法不能隐藏线程的实例方法”。
我不明白这意味着什么,所以请帮助我。
public class hello extends Thread {
public static synchronized void run() {
for(int i=0;i<1000;i++)
System.out.println(i);
}
public static void main(String[] args) {
hello t1 = new hello();
hello t2 = new hello();
t1.start();
t2.start();
}
}
'run()'不是*静态*方法。它是'Runnable'接口中声明的方法,然后由'Thread'实现。 – TheLostMind