officeba > 单独文章


细心了:scjp考题中的种种陷阱

(1) Two public classes in the same file. (illegal)

  同一个文件里有两个public类。(非法)

  (2) Main method calling a non-static method. (illegal)

  在main(String[] args)方法内调用一个非静态方法。(非法)

  (3) Methods with the same name as the constructor(s). (这种题常有)

  与Constructor(s)有相同名字的方法。

  (4) Thread initiation with classes that do not have a run() method.

  (常考之题) 初始化了一个没有run()方法的线程类。

  (5) Local inner classes trying to access non-final vars. (illegal)

  内部类尝试访问非final变量(非法)

  (6) Case statements with values out of permissible range. (byte,int, short,chat)

  选择语句case中,没有使用允许的值。如(byte,int,short,char)等

  (7) Math class being an option for immutable classes !! (totally wrong!)

  Math类作为不可改变类。(完全错误) (请提意见)

  (8) instanceOf is not same as instanceof.

  instanceOf 不是 instanceof。

  (9) Private constructors. (legal)

  私有 的Constructor。 (合法)

  (10)An assignment statement which looks like a comparison.

  一个 赋值语句 看起来像 比较语句。

  比如说if(a=true),和if(a==true)。对于这种题眼睛亮一点。

  (11)System.exit() in try-catch-finally blocks. (finally 不会执行)

  在try-catch-final块中的退出语句。 (finally不会执行)

  (12)Order of try-catch-finally blocks matters. (若顺序错的话: error: No try before catch)

  try-catch-final块的顺序问题。

  (13)main() can be declared final. (OK)

  main()方法 可以声明为 final.

  (14) -0.0 == 0.0 is true.

  (15)A class without abstract methods can still be declared abstract

  没有抽象方法的类,仍然可以定义为抽象类。


第1页 | 第2页 | 第3页

声明:欢迎各大网站转载本站文章,还请保留一条能直接指向本站的超级链接,谢谢!

时间:2007-05-08 07:54:10,点击:65824


【OfficeBa论坛】:阅读本文时遇到了什么问题,可以到论坛进行交流!Excel专家邮件:342327115@qq.com(大家在Excel使用中遇到什么问题,可以咨询此邮箱)。

【声明】:以上文章或资料除注明为Office自创或编辑整理外,均为各方收集或网友推荐所得。其中摘录的内容以共享、研究为目的,不存在任何商业考虑。如有任何异议,请与本站联系,本站确认后将立即撤下。谢谢您的支持与理解!


相关评论

我要评论

评论内容