這是我的代碼:嵌套類沒有確定由外部類的方法
class Outer
{
static int x=10;
static
{
class Inner
{
void disp()
{
System.out.println(x);
}
}
}
void outdisp()
{
for(int i=0;i<5;i++)
{
Inner in = new Inner();
in.disp();
}
}
public static void main(String []args)
{
Outer out = new Outer();
out.outdisp();
}
}
我只是想知道爲什麼方法outdisp()
不能識別在這種情況下類Inner
,而它如果我將Inner
類聲明爲靜態而不是靜態塊,那麼可以正常工作嗎?