pra*_*y G 0 java multithreading
我是多线程编程的新手,当我将该run()方法声明为static时,将编译器错误称为
"这种静态方法无法隐藏Thread中的实例方法".
我不明白这意味着什么,所以请帮助我.
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 Code Online (Sandbox Code Playgroud)
它不一定与多线程编程相关,一般来说它也适用于Java.如果你有一个班级:
public class MySuperclass {
public void myMethod() {
//do stuff
}
}
Run Code Online (Sandbox Code Playgroud)
你不能覆盖它以使其静止:
public class MySubclass extends MySuperclass {
public static void myMethod() {
//do other stuff
}
}
Run Code Online (Sandbox Code Playgroud)
这是不允许的.这就是错误信息的含义.