示例代码
public class Outer { private String name = "qiudajiang"; static class Inner{ private int age = 21; private String name = "qiudashuai"; private static String address = "xxx"; void show(){ //访问外部类的属性要先创建外部类对象 Outer outer = new Outer(); System.out.println(outer.name); //静态内部类访问静态内部属性通过类名访问 System.out.println(Inner.address); System.out.println(name); System.out.println(age); } } }
测试代码
public class OuterTest { public static void main(String[] args) { //Outer outer = new Outer(); //Outer.Inner inner = outer.new Inner(); //inner.show(); Outer.Inner inner = new Outer.Inner(); inner.show(); } }