public class HelloWorld {
public class Outer{
private int a=99;
public class Inner{
int b=2;
public void test(){
System.out.println("访问外部类中的a:"+a);
System.out.println("访问内部类中的b:"+b);
}
}
}
public static void main(String[] args) {
HelloWorld g=new HelloWorld();
Outer h=g.new Outer();
Outer.Inner j=g.h.new Outer.Inner();
h.test();
}
}
public class HelloWorld { private int a=99; public class Inner{ int b=2; public void test(){ System.out.println("weibua:"+a); System.out.println("neibub:"+b); } } public static void main(String[] args) { HelloWorld hello=new HelloWorld(); Inner inn = hello.new Inner(); inn.test(); } }
把 Outer class去掉。编程不是多层嵌套。
嗯,想理一下关系