Java中的Static

1、Static是静态的意思,如果main函数是static类型的,则新写一个类的时候,成员函数或者成员变量如果不是static类型的,则不能通过“类名+.”的方式直接调用,必须通过手动new一个对象,通过"对象+."的方式来访问

2、写了一个不带static的类(即动态类),在main函数中给这个类new的时候时候,提示:“No enclosing instance of type dm1 is accessible. Must qualify the allocation with an enclosing instance of type dm1 (e.g. x.new A() where x is an instance of dm1).”,

这是因为新写的类是一个动态的内部类,创建这样的对象必须有实例与之对应,程序是在静态方法中直接调用动态内部类会报这样错误。   这样的错误好比类中的静态方法不能直接调用动态方法。可以把该内部类声明为static。或者不要在静态方法中调用

posted @ 2018-03-29 14:45  一字节  阅读(158)  评论(0编辑  收藏  举报