-
不依赖外部对象,可直接创建或通过类名访问,可声明静态成员
-
-
Outer.Inner inner =new Outer.inner();
-
Outer.Inner.show();
//外部类
public class Outer {
private String name = "xxx";
private int age =60;
//静态内部类:+static和外部类级别相同
static class Inner{
private String address = "上海";
private int phone = 100;
//静态成员
private static int count=10000;
public void show(){
//调用外部类的属性
//先new一个外部类
Outer outer = new Outer();
//调用外部类对象属性
System.out.println(outer.name);
System.out.println(outer.age);
//调用静态内部类的属性
System.out.println(address);
System.out.println(phone);
//调用静态内部类的静态方法
System.out.println(Inner.count);
}
?
}
}
public class TestOuter {
public static void main(String[] args) {
//创建内部类对象
Outer.Inner inner = new Outer.Inner();
//调用方法
inner.show();
}
}