import java.lang.*;
class mythread implements Runnable {
Thread t1;
String name = "";
mythread(String thname){
name = thname;
t1 = new Thread(this, name);
System.out.println("Child thread starting" + t1 );
}
@Override
public void run() {
for(int i = 5 ; i > 0 ;i--){
System.out.println("Name Of Thread" + t1 + i);
}
}
class t {
public static void main(String args[]) {
mythread m1 = new mythread("Child Thread 1");
mythread m2 = new mythread("Child Thread 2");
try {
for(int i = 5 ; i > 0 ;i--) {
System.out.println("Main Thread" + i);
Thread.sleep(2000);
博客讨论了在Java中遇到内部类非法静态声明的问题,具体表现为错误提示'Illegical static declaration in inner class'。问题出现在内部类`t`尝试访问静态变量时。解决方案是移除内部类`t`或将其声明为静态。示例代码展示了如何修正这个问题。
最低0.47元/天 解锁文章
1542

被折叠的 条评论
为什么被折叠?



