package shubh;
class thread5
{
static class a7 extends Thread
{
public void run()
{
for(int i=0;i<=10;i++)
{
System.out.println(i);
}
}
}
static class a8 implements Runnable
{
public void run()
{
for(int i=21;i<=30;i++)
{
System.out.println(i);
}
}
}
public static void main(String arg[])
{
a7 a=new a7();
a.start();
a8 b=new a8();
Thread th=new Thread(b);
th.start();
for(int i=40;i<=50;i++)
{
System.out.println(i);
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我从2个嵌套类中删除静态关键字时它给出错误非静态变量无法从静态上下文中引用任何人都可以解释这个错误的含义或为什么有必要将嵌套类作为静态
如果你删除static那么你需要一个实际的对象来实例化内部类.即
new thread5().new a7();