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);
}
}红色字那一行为什么 他说找不到符号啊
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);
}
}红色字那一行为什么 他说找不到符号啊
Outer.Inner z=new Outer.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);
}
}
必须要先实例话外面那个类啊?
有没有别的方法?除了static```