Java类、接口定义相关
时间:2010-10-18 来源:hjhnju
今天的一点收获
- /**
- * 以下程序编译错误
- * Java类的成员变量会被自动初始化,但局部变量不会被自动初始化
- */
- public class Test {
- public static void main(String[] args){
- int x;
- System.out.println(x); //The local variable x may not have been initialized
- }
- }
- /**
-
* 以下定义正确与否
*/ - abstract public class TestProtected {}//Right!
- final public class Test4{}//Right!
- //protected 不能用来定义类或接口
- protected class Test{}//Error!
- //非嵌套类和接口都不能使用static定义
- public static interface Test{}//Error!
- static class Test{} //Error!
- //注:只有在内部类时可以定义静态内部类
相关阅读 更多 +