<dfn id="w48us"></dfn><ul id="w48us"></ul>
  • <ul id="w48us"></ul>
  • <del id="w48us"></del>
    <ul id="w48us"></ul>
  • SUN認證Java2程序員考試題及答案

    時間:2024-09-09 23:57:03 SUN認證 我要投稿
    • 相關推薦

    SUN認證Java2程序員考試題及答案

      Java帶給你的并不僅僅是面向對象、開放、平臺無關、易用、安全和“Write once, run anywhere”等軟件開發方面的優勢,更重要的一點是,它提供了一種新穎的表達思想的方式,一種全新的思維模式。下面一起來看看Java2程序員考試題及答案!

    SUN認證Java2程序員考試題及答案

      例題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將不會被喚醒。

    【SUN認證Java2程序員考試題及答案】相關文章:

    sun認證java程序員07-20

    Sun java認證考試答案11-06

    SUN國際認證試題及答案09-20

    Sun-Java程序員認證考試題庫06-22

    SUN認證JAVA程序員簡介09-29

    sun公司國際認證試題及答案09-10

    sun java認證考試題庫08-24

    2017年Sun-Java程序員認證考試題庫05-29

    sun認證java程序員考試科目08-22

    Sun java認證考試真題答案09-25

    主站蜘蛛池模板: 91国内揄拍国内精品对白不卡| 国产精品三级在线| 精品国际久久久久999波多野| 91热成人精品国产免费| 亚洲精品国产精品乱码不99| 2021国产精品视频网站| 日韩精品一区二区三区中文| 国产成人精品在线观看| avtt天堂网久久精品| 日韩精品欧美亚洲| 2020最新久久久视精品爱| 久久精品水蜜桃av综合天堂| 午夜成人精品福利网站在线观看| 91大神精品全国在线观看| 国产成人精品免费视频大| 亚洲AV日韩精品久久久久久久| 精品国产黑色丝袜高跟鞋| 中文精品久久久久国产网址| 91精品国产自产在线观看永久| 综合精品欧美日韩国产在线| 国内精品久久久久影院网站| 国产日韩精品欧美一区喷水| 亚洲精品偷拍视频免费观看| 国内精品久久久久久久影视麻豆| 精品一卡2卡三卡4卡免费视频| 无码人妻精品一区二区三区在线| 久久久精品国产亚洲成人满18免费网站 | 国产精品熟女福利久久AV| 国产高清在线精品一区| 精品免费人成视频app| 亚洲国产一二三精品无码| 人妻少妇看A偷人无码精品| 精品国产综合区久久久久久| 国产成人精品无人区一区| 尤物国产在线精品福利一区| 国产精品怡红院永久免费| 国产成人亚洲精品| 2021国产成人精品国产| 97久久国产亚洲精品超碰热 | 99re6这里有精品热视频| 国产欧美亚洲精品A|