class Outer {
 int x=1;
 Outer y=new Outer(); 
  public class Inner{
   int x=2;
  }
}class c{
  public static void main(String arg[]){
   Outer y=new Outer();
   System.out.println(y.x);
   System.out.print(y.y.x);
   Outer.Inner z=Outer.new Inner();
   System.out.print(z.x);
  }
}红色字那一行为什么 他说找不到符号啊

解决方案 »

  1.   

    这样写:
    Outer.Inner z=new Outer.Inner(); 
      

  2.   

    这样又显示 需要包含 Outer.Inner 的封闭实例
    还是不行啊
      

  3.   

    应该这样调用,因为Inner类不是static类型的,Outer.Inner z = y.new Inner();
    你程序还有点问题,帮你改了改:class Outer {
    int x = 1;
    // Outer y=new Outer(); 堆栈溢出,必须注释掉
    public class Inner {
    int x = 2;
    }
    }public class C {
    public static void main(String arg[]) {
    Outer y = new Outer();
    System.out.println(y.x);
    // System.out.print(y.y.x);
    Outer.Inner z = y.new Inner();
    System.out.print(z.x);
    }
    }
      

  4.   

    请教下```是不是内部类要实例化的话
    必须要先实例话外面那个类啊?
    有没有别的方法?除了static```