package staticclass;
/*
* @author: wjf
* @version: 2016年3月24日 下午10:01:21
*/
public class TestStaticClass {
private static int aa=2;
class Test{
/*
* 在非静态类中,只能通过 加 final 定义静态成员变量
* 在非静态类中,不能定义静态方法
*/
static final int a=1;
public int getA(){
return a;
}
public int b=2;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
// 对于非静内部类,必须绑定一个外部对象。先定义外部对象再定义内部类对象
// 对于静态内部类,不需要把内部对象绑定到外部对象上。
TestStaticClass tt=new TestStaticClass();
Test t=tt.new Test();
// 这里 静态类中的 非静态成员居然可以通过 . 直接访问
System.out.println(t.b);
System.out.println();
System.out.println(TestStaticClass.Test.a);
}
}
Java 静态内部类学习
最新推荐文章于 2023-05-29 17:53:03 发布