【发布时间】:2012-12-26 20:32:09
【问题描述】:
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);
}
}
}
当我从 2 个嵌套类中删除 static 关键字时,它给出了错误 non static variable cannot be referenced from a static context 谁能解释一下这个错误的含义或为什么必须给出嵌套类作为静态
【问题讨论】: