亚洲AV日韩AⅤ综合手机在线观看,激情婷婷久久综合色,欧美色五月婷婷久久,久久国产精品99久久人人澡

  • <abbr id="uk6uq"><abbr id="uk6uq"></abbr></abbr>
  • <tbody id="uk6uq"></tbody>
  • SUN認(rèn)證Java2程序員考試題及答案

    時(shí)間:2020-09-09 14:32:55 SUN認(rèn)證 我要投稿

    SUN認(rèn)證Java2程序員考試題及答案

      Java帶給你的并不僅僅是面向?qū)ο、開放、平臺(tái)無(wú)關(guān)、易用、安全和“Write once, run anywhere”等軟件開發(fā)方面的優(yōu)勢(shì),更重要的一點(diǎn)是,它提供了一種新穎的表達(dá)思想的方式,一種全新的思維模式。下面一起來(lái)看看Java2程序員考試題及答案!

    SUN認(rèn)證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

      點(diǎn)評(píng):Java中的標(biāo)示符必須是字母、美元符($)或下劃線(_)開頭。關(guān)鍵字與保留字不能作為標(biāo)示符。選項(xiàng)C中的const是Java的保留字,所以不能作標(biāo)示符。選項(xiàng)E中的3_case以數(shù)字開頭,違反了Java的規(guī)則。

      例題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

      點(diǎn)評(píng):在Java中垃圾收集是不能被強(qiáng)迫立即執(zhí)行的。調(diào)用System.gc()或Runtime.gc()靜態(tài)方法不能保證垃圾收集器的立即執(zhí)行,因?yàn)椋苍S存在著更高優(yōu)先級(jí)的線程。所以選項(xiàng)B、D不正確。選項(xiàng)C的錯(cuò)誤在于,System.gc()方法是不接受參數(shù)的。選項(xiàng)E中的方法可以使對(duì)象在下次垃圾收集器運(yùn)行時(shí)被收集。

      例題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

      點(diǎn)評(píng):在第12行,16位長(zhǎng)的char型變量ch在編譯時(shí)會(huì)自動(dòng)轉(zhuǎn)化為一個(gè)32位長(zhǎng)的int型,并在運(yùn)行時(shí)傳給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

      點(diǎn)評(píng):選項(xiàng)A錯(cuò),因?yàn)閕f語(yǔ)句后需要一個(gè)boolean類型的表達(dá)式。邏輯操作有^、&、| 和 &&、||,但是“&|”是非法的,所以選項(xiàng)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

      點(diǎn)評(píng): 在Java中代碼重用有兩種可能的'方式,即組合(“has a”關(guān)系)和繼承(“is a”關(guān)系)。“has a”關(guān)系是通過(guò)定義類的屬性的方式實(shí)現(xiàn)的;而“is a”關(guān)系是通過(guò)類繼承實(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 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

      點(diǎn)評(píng):TreeSet類實(shí)現(xiàn)了Set接口。Set的特點(diǎn)是其中的元素惟一,選項(xiàng)C正確。由于采用了樹形存儲(chǔ)方式,將元素有序地組織起來(lái),所以選項(xiàng)A也正確。

      例題7:

      True or False: Readers have methods that can read and return floats and doubles.

      A. Ture

      B. False

      解答:B

      點(diǎn)評(píng): Reader/Writer只處理Unicode字符的輸入輸出。float和double可以通過(guò)stream進(jìn)行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

      點(diǎn)評(píng):drawString(String str, int x, int y)方法是使用當(dāng)前的顏色和字符,將str的內(nèi)容顯示出來(lái),并且最左的字符的基線從(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

      點(diǎn)評(píng):在Java中,每一個(gè)對(duì)象都有鎖。任何時(shí)候,該鎖都至多由一個(gè)線程控制。由于alias1與alias2指向同一對(duì)象Z,在執(zhí)行第11行前,線程擁有對(duì)象Z的鎖。在執(zhí)行完第11行以后,該線程釋放了對(duì)象Z的鎖,進(jìn)入等待池。但此后沒有線程調(diào)用對(duì)象Z的notify()和notifyAll()方法,所以該進(jìn)程一直處于等待狀態(tài),沒有輸出。

      例題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

      點(diǎn)評(píng):由于類是public,所以文件名必須與之對(duì)應(yīng),選項(xiàng)A正確。如果不在2、3行之間加上super(nrows,ncols)的話,則會(huì)調(diào)用無(wú)參數(shù)構(gòu)建器TextArea(), 使nrows、ncols信息丟失,故選項(xiàng)B正確。在Java2中,所有的事件處理方法都不返回值,選項(xiàng)C、D錯(cuò)誤。選項(xiàng)E正確,因?yàn)槿绻患觭uper.processTextEvent(te),注冊(cè)的listener將不會(huì)被喚醒。

    【SUN認(rèn)證Java2程序員考試題及答案】相關(guān)文章:

    2017年SUN-Java程序員認(rèn)證考試題庫(kù)及答案05-19

    SUN國(guó)際認(rèn)證試題及答案11-04

    sun認(rèn)證java程序員10-25

    sun認(rèn)證java程序員考試題庫(kù)05-06

    sun公司國(guó)際認(rèn)證試題及答案11-04

    Sun-Java程序員認(rèn)證考試題庫(kù)11-12

    SUN認(rèn)證JAVA程序員簡(jiǎn)介05-12

    Sun java認(rèn)證考試答案11-12

    2017年SUN認(rèn)證Java程序員考試題庫(kù)05-06