public class TestStaticInner {
public static void main(String[] args){
//Outer outer = new Outer();
//outer.get();
//Outer.get(1);
Outer.Inner in = new Outer.Inner();
in.get();//通过其他类访问内部类
}
}
class Outer {
private int num = 3;
public static int index = 4;
static class Inner{//静态内部类
int num = 5;
static int index = 6;
public void get(){
int num = 7;
System.out.println(num);
System.out.println(index);
System.out.println(this.num);
System.out.println(Outer.index);//可以直接访问外部类的静态私有属性
//System.out.println(Outer.num);---------> Error!!不能访问外部类的非静态属性
}
}
public void get(){
Inner in = new Inner();
in.get();
System.out.println("this is outer get !");
}
public static void get(int w){
Inner in = new Inner();
in.get();
System.out.println("this is outer static set !");
}
}
StaticInner
最新推荐文章于 2023-10-16 16:36:58 发布