全國(guó)軟考程序員考試部分例題_第1頁(yè)
全國(guó)軟考程序員考試部分例題_第2頁(yè)
全國(guó)軟考程序員考試部分例題_第3頁(yè)
全國(guó)軟考程序員考試部分例題_第4頁(yè)
全國(guó)軟考程序員考試部分例題_第5頁(yè)
已閱讀5頁(yè),還剩16頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、全國(guó)軟考程序員考試部分例題全國(guó)軟考程序員考試部分例題全國(guó)軟考程序員考試部分例題例題1:choose the three valid ide ntifiers from those listed below.a. idolikethel ongn ameclassb. $bytec. constd. _oke. 3_case解答:a, b, d點(diǎn)評(píng):java中的標(biāo)示符必須是字母、美元符($)或下劃線(xiàn)(_)開(kāi)頭。關(guān)鍵字與保留字不能作為標(biāo)示符。選項(xiàng)c中的const是java的保留 字,所以不能作標(biāo)示符。選項(xiàng)e中的3_case以數(shù)字開(kāi)頭,違反了 java 的規(guī)則。例題2:how can you for

2、ce garbage collecti on of an object?a. garbage collecti on cannot be forcedb. call system.gc().c. call system.gc(), pass ing in a refere nee to the object tobe garbage collected.d. call run time.gc().e. set all referen ces to the object to new values( n ull, forexample).解答:a點(diǎn)評(píng):在java中垃圾收集是不能被強(qiáng)迫立即執(zhí)行的。

3、調(diào)用system.gc()或runtime.gc()靜態(tài)方法不能保證垃圾收集器的立即執(zhí) 行,因?yàn)?,也許存在著更高優(yōu)先級(jí)的線(xiàn)程。所以選項(xiàng)b、d不正確。選項(xiàng)c的錯(cuò)誤在于,system.gc()方法是不接受參數(shù)的。選項(xiàng)e中的方法可以使對(duì)象在下次垃圾收集器運(yùn)行時(shí)被收集。例題3:con sider the follow ing class:1. class test(i nt i) 2. void test(i nt i) 3. system.out.pri ntln( i am an in t.);4. 5. void test(stri ng s) 6. system.out.pri ntl n(

4、i am a stri ng.);8.9. public static void mai n(stri ng args) 10. test t=new test();11. char ch= y12. t.test(ch);13. 14. which of the stateme nts below is true?(choose on e.)a. li ne 5 will not compile, because void methods cannot be overridde n.b. li ne 12 will n ot compile, because there is no vers

5、 ion of test() that rakes a char argume nt.c. the code will compile but will throw an excepti on at line 12.d. the code will compile and produce the follow ing output:i am an int.e. the code will compile and produce the follow ing output:i am a stri ng.解答:d點(diǎn)評(píng):在第12行,16位長(zhǎng)的char型變量ch在編譯時(shí)會(huì)自動(dòng)轉(zhuǎn)化為一個(gè)32位長(zhǎng)的int

6、型,并在運(yùn)行時(shí)傳給void test(int i)方法。例題4:which of the followi ng lines of code will compile withouterror ?a. i nt i=0;if (i) system.out.pr intln(hi );b.boolea n b=true;boolea n b2二true;if(b=b2) system.out.pr intln( so true ); i=1;int j=2;if(i=1| j=2)system.out.pr in tl n( ok ); i=1;int j=2;if (i=1

7、| j=2)system.out.pr intln( ok );解答:b, c點(diǎn)評(píng):選項(xiàng)a錯(cuò),因?yàn)閕f語(yǔ)句后需要一個(gè)boolean類(lèi)型的表達(dá)式。邏輯操作有 tandle extends shape b. public in terface colorable public class shape impleme nts colorable c. public class species public class ani malprivate species species;d. i nteface comp onent class container impleme nts comp onen

8、t private comp onen t childre n;解答:d, e點(diǎn)評(píng):在java中代碼重用有兩種可能的方式,即組合(has a 關(guān)系)和繼承(is a關(guān)系)。has a關(guān)系是通過(guò)定義類(lèi)的屬性的方 式實(shí)現(xiàn)的;而is a關(guān)系是通過(guò)類(lèi)繼承實(shí)現(xiàn)的。本例中選項(xiàng)a、b、c體現(xiàn)了 is a關(guān)系;選項(xiàng)d、e體現(xiàn)了 has a關(guān)系。例題6:which two stateme nts are true for the class java.util.treeset?(choose two)a. the eleme nts in the collecti on are ordered.b. the c

9、ollectio n is guara nteed to be immutable.c. the elementsin the collectionare guaranteedto beuniq ue.d. the elements unique key.e. the elements synchroni zed解答:a, cin the collectionin the collectionare accessed using aare guaranteedto be點(diǎn)評(píng):treeset類(lèi)實(shí)現(xiàn)了 set接口。set的特點(diǎn)是其中的元素惟一 選項(xiàng)c正確。由于采用了樹(shù)形存儲(chǔ)方式,將元素有序地組織起

10、來(lái),所 以選項(xiàng)a也正確。例題7:true or false: readers have methods that can read and retur n floats and doubles.a. tureb. false解答:bfloat點(diǎn)評(píng):reader/writer 只處理unicode字符的輸入輸出 和double 可以通過(guò)stream 進(jìn)行i/o.what does the follow ingpai nt() method draw?1. public void pain graphics g) 2. g.drawstri ng( any questi on ,10, 0);a.

11、 the string any question? , with its top-left corner at 10,0b. a little squiggle coming down from the top of the comp onent.解答:b點(diǎn)評(píng):drawstring(string str, int x, int y)方法是使用當(dāng)前的顏色和字符,將str的內(nèi)容顯示出來(lái),并且最左的字符的基線(xiàn)從(x,y)開(kāi) 始。在本題中,y=0 ,所以基線(xiàn)位于最頂端。我們只能看到下行字母 的一部分,即字母y、q的下半部分。例題9:what happens when you try to compil

12、e and run thefollowi ng applicati on? choose all correct opti ons.1. public class z 2. public static void mai n(stri ng args) 3. new z();4. 5.5. z() 6. z aliasl = this;7. z alias2 = this;8. synchroni zed(aliasl) 9. try 10. alias2.wait();11. system.out.pri ntl n( done wait ing );12. 13. catch (in ter

13、ruptedexcepti on e) 14. system.out.pri ntl n( in terrupted );15. 16. catch (excepti on e) 17. system.out.pri ntln( other excepti on );18. 19. fin ally 20. system.out.pri ntl n(fin ally );21. 22. 23. system.out.pri ntl n( all done );24. 25. a. the applicati on compiles but does n t print anything.b.

14、the applicatio n compiles and print done wait ingc. the applicatio n compiles and print fin allyd. the applicatio n compiles and print all donee. the applicatio n compiles and print in terrupted解答:a點(diǎn)評(píng):在java中,每一個(gè)對(duì)象都有鎖。任何時(shí)候,該鎖都至多 由一個(gè)線(xiàn)程控制。由于aliasl與alias2指向同一對(duì)象z,在執(zhí)行第 11行前,線(xiàn)程擁有對(duì)象z的鎖。在執(zhí)行完第11行以后,該線(xiàn)程釋放 了對(duì)象z

15、的鎖,進(jìn)入等待池。但此后沒(méi)有線(xiàn)程調(diào)用對(duì)象z的notify。和notifyall()方法,所以該進(jìn)程一直處于等待狀態(tài),沒(méi)有輸出。例題10 :which statement or statements are true about the code listed below? choose three.1. public class mytextarea exte nds textarea 2. public mytextarea(i nt n rows, int n cols) 3. en ableeve nts(awteve nt.texteve nt_mask);4. 5.5. public

16、 void processtexteve nt(texteve nt te) 6. system.out.pri ntln( process ing a text eve nt.);7. 8. a file calledbe made toa. the source code must appear inmytextarea.javab. betweenlines 2 and 3, a call should super( nrows, n cols) so that the new comp onent will have the correct size.c. at line 6, the retur n type of processtexteve nt() should be declared boolea n, not void.d. betweenlines7 and8, thefollowingcodeshouldappear: retur n true.e. betweenlines7 and8, thefollowingcodeshouldappear: super

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論