Sun認證Java程序員(SCJP)考題常見陷阱集合

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

Sun認證Java程序員(SCJP)考題常見陷阱集合

同一個文件裏有兩個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)() 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.

沒有抽象方法的類,仍然可以定義爲抽象類。