計算機技術與軟件水平考試程序員考證例題內容簡介
計算機技術與軟件水平考試程序員考證例題
例題1:
Choose the tHRee valid identifIErs from those listed below.
A. IDoLikeTheLongNameClass
B. $byte
C. const
D. _ok
E. 3_case
解答:A, B, D
點評:Java中的標示符必須是字母、美元符($)或下劃線(_)開頭。關鍵字與保留字不能作為標示符。選項C中的const是Java的保留字,所以不能作標示符。選項E中的3_case以數字開頭,違反了Java的規則。
例題2:
How can you force garbage collection of an object?
A. Garbage collection cannot be forced
B. Call System.gc().
C. Call System.gc(), passing in a reference to the object to be garbage collected.
D. Call Runtime.gc().
E. Set all references to the object to new values(null, for example).
解答:A
點評:在Java中垃圾收集是不能被強迫立即執行的。調用System.gc()或Runtime.gc()靜態方法不能保證垃圾收集器的立即執行,因為,也許存在著更高優先級的線程。所以選項B、D不正確。選項C的錯誤在於,System.gc()方法是不接受參數的。選項E中的方法可以使對象在下次垃圾收集器運行時被收集。
例題3:
Consider the following class:
1. class Test(int i) {
2. void test(int i) {
3. System.out.println(“I am an int.”);
4. }
5. void test(String s) {
6. System.out.println(“I am a string.”);
7. }
8.
9. public static void main(String args[]) {
10. Test t=new Test();
11. char ch=“y”;
12. t.test(ch);
13. }
14. }
Which of the statements below is true?(Choose one.)
A. Line 5 will not compile, because void methods cannot be overridden.
B. Line 12 will not compile, because there is no version of test() that rakes a char argument.
C. The code will compile but will tHRow an exception at line 12.
D. The code will compile and produce the following output: I am an int.
E. The code will compile and produce the following output: I am a String.
解答:D
點評:在第12行,16位長的char型變量ch在編譯時會自動轉化為一個32位長的int型,並在運行時傳給void test(int i)方法。
例題4:
Which of the following lines of code will compile wIThout error?
A.
int i=0;
if (i) {
System.out.println(“Hi”);
}
B.
boolean b=true;
boolean b2=true;
if(b==b2) {
System.out.println(“So true”);
}
..............................