中文一二三区_九九在线中文字幕无码_国产一二区av_38激情网_欧美一区=区三区_亚洲高清免费观看在线视频

首頁 > 考試輔導 > 計算機考試 > 軟件水平考試 > 軟件試題庫 > 全國軟考程序員考試部分例題

全國軟考程序員考試部分例題

例題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”);

   

   }

   c.

   int i=1;

   int j=2;

   if(i==1|| j==2)

   system.out.println(“ok”);

   

   d.

   int i=1;

   int j=2;

   if (i==1 &| j==2)

   system.out.println(“ok”);

   解答:b, c

   

   點評:選項a錯,因為if語句后需要一個boolean類型的表達式。邏輯操作有^、&、| 和 &&、||,但是“&|”是非法的,所以選項d不正確。 


   例題5: 
   
   which two demonstrate a "has a" relationship? (choose two)

   a. public interface person { }

   public class employee extends person{ }

   

   b. public interface shape { }

   public interface rectandle extends shape { }

   c. public interface colorable { }

   public class shape implements colorable

   

   { }

   d. public class species{ }

   public class animal{private species species;}

   e. interface component{ }

   class container implements component{

   private component[] children;

   

   }

   解答:d, e

   點評: 在java中代碼重用有兩種可能的方式,即組合(“has a”關系)和繼承(“is a”關系)。“has a”關系是通過定義類的屬性的方式實現的;而“is a”關系是通過類繼承實現的。本例中選項a、b、c體現了“is a”關系;選項d、e體現了“has a”關系。 

例題6:

   which two statements are true for the class java.util.treeset? (choose two)

   a. the elements in the collection are ordered.

   b. the collection is guaranteed to be immutable.

   c. the elements in the collection are guaranteed to be unique.

   d. the elements in the collection are accessed using a unique key.

   e. the elements in the collection are guaranteed to be synchronized 

   解答:a, c

   點評:treeset類實現了set接口。set的特點是其中的元素惟一,選項c正確。由于采用了樹形存儲方式,將元素有序地組織起來,所以選項a也正確。

   例題7:

   true or false: readers have methods that can read and return floats and doubles.

   a. ture

   b. false

   解答:b

   點評: reader/writer只處理unicode字符的輸入輸出。float和double可以通過stream進行i/o. 
   

   例題8:

   what does the following

   paint() method draw?

   1. public void paint(graphics g) {

   2. g.drawstring(“any question”, 10, 0);

   3. }

   a. the string “any question?”, with its top-left corner at 10,0

   b. a little squiggle coming down from the top of the component.

   

   解答:b

   點評:drawstring(string str, int x, int y)方法是使用當前的顏色和字符,將str的內容顯示出來,并且最左的字符的基線從(x,y)開始。在本題中,y=0,所以基線位于最頂端。我們只能看到下行字母的一部分,即字母‘y’、‘q’的下半部分。 

   例題9:

   what happens when you try to compile and run the following application? choose all correct options.

   1. public class z {

   2. public static void main(string[] args) {

   3. new z();

   4. }

   5.

   6. z() {

   7. z alias1 = this;

   8. z alias2 = this;

   9. synchronized(alias1) {

   10. try {

   11. alias2.wait();

   12. system.out.println(“done waiting”);

   

   13. }

   14. catch (interruptedexception e) {

   15. system.out.println(“interr

   upted”);

   16. }

   17. catch (exception e) {

   18. system.out.println(“other exception”);

   19. }

   20. finally {

   21. system.out.println

   (“finally”);

   22. }

   23. }

   24. system.out.println(“all done”);

   25. }

   26. }

   a. the application compiles but doesn t print anything.

   b. the application compiles and print “done waiting”

   c. the application compiles and print “finally”

   d. the application compiles and print “all done”

   e. the application compiles and print “interrupted” 
   

   解答:a

   點評:在java中,每一個對象都有鎖。任何時候,該鎖都至多由一個線程控制。由于alias1與alias2指向同一對象z,在執行第11行前,線程擁有對象z的鎖。在執行完第11行以后,該線程釋放了對象z的鎖,進入等待池。但此后沒有線程調用對象z的notify()和notifyall()方法,所以該進程一直處于等待狀態,沒有輸出。 
   

   例題10:

   which statement or statements are true about the code listed below? choose three.

   1. public class mytextarea extends textarea {

   2. public mytextarea(int nrows, int ncols) {

   3. enableevents(awtevent.

   text_ 

   event_mask);

   4. }

   5.

   6. public void processtextevent 
 

   (textevent te) {

   7. system.out.println(“processing a text event.”);

   8. }

   9. }

   a. the source code must appear in a file called mytextarea.java

   b. between lines 2 and 3, a call should be made to super(nrows, ncols) so that the new component will have the correct size.

   c. at line 6, the return type of processtextevent() should be declared boolean, not void.

   d. between lines 7 and 8, the following code should appear: return true.

   e. between lines 7 and 8, the following code should appear: super.processtextevent(te). 
   

   解答:a, b, e

   點評:由于類是public,所以文件名必須與之對應,選項a正確。如果不在2、3行之間加上super(nrows,ncols)的話,則會調用無參數構建器textarea(), 使nrows、ncols信息丟失,故選項b正確。在java2中,所有的事件處理方法都不返回值,選項c、d錯誤。選項e正確,因為如果不加super.processtextevent(te),注冊的listener將不會被喚醒。

主站蜘蛛池模板: 成人欧美视频在线观看 | 男女多P混交群体交乱A片 | 欧美100集久久久 | 91精品视频在线看 | 成人免费精品 | 中国一级簧色带免费看 | 欧美大逼视频 | 欧美黑人牲交videossexeso | 国产精品视频二区三区 | 久草视频中文 | 午夜成人爽爽爽视频在线观看 | 亚洲精品免费一区二区三区 | 国产一区色 | 猛烈顶弄H禁欲老师H春潮视频 | 99热超碰在线 | 无码人妻少妇久久中文字幕蜜桃 | 欧美1区| 日韩欧美成人影院 | 白浆一区二区三区 | 国产欧美高清在线观看 | 久艹在线免费观看 | 最近韩国动漫hd免费观看 | 欧美野战 | 亚洲成熟老女毛茸茸 | 女人内谢aaaa免费视频 | 国产成人亚洲综合网色欲网 | 国产高清不卡一区二区在线视频 | 免费一级全黄少妇性色生活片 | 91丨porny丨蝌蚪 | 国产精品aⅴ | aaaaaaaaa在线观看| 久久伊人av| 国产精品一区二区AV蜜芽 | 色综合久久中文字幕有码 | 免费看少妇高潮一级毛片特黄 | 午夜爽爽爽男女免费观看影院 | 91精品欧美福利免费观看 | 国产精品丝袜久久久久久不卡 | 国产精品99久久久久人中文网介绍 | 亚洲av成人无码网站 | 日韩高清在线播放 |