Java程序員認(rèn)證模擬題及詳細(xì)分析(3)

字號(hào):

續(xù):Java程序員認(rèn)證模擬題及分析(1) 和(2)
     51. Which correctly create an array of five empty Strings?
     A. String a[] = new String[5];
     for (int i=0;i<5;a[i ]=””);
     B. String a []={“”,””,””,””,””};
     C. String a[5];
     D. String [5] a;
     E. String [] a = new String[5];
     for (int i = 0 ;i<5;a[i ] = null);
     52. Which cannot be added to a Container?
     A. an Applet
     B. a Component
     C. a Container
     D. a MenuComponent
     E. a panel
     53. Which is the return value of Event listener?s method?
     A. String B. AWTEvent C. void D. int
     54. If we implements MouseListener, which is corrected argument of its method? (short answer)
     55. Use the operator “>>” and “>>>”. Which statement is true?
     A. 1010 0000 0000 0000 0000 0000 0000 0000 >> 4 give
     0000 1010 0000 0000 0000 0000 0000 0000
     B. 1010 0000 0000 0000 0000 0000 0000 0000 >> 4 give
     1111 1010 0000 0000 0000 0000 0000 0000
     C. 1010 0000 0000 0000 0000 0000 0000 0000 >>> 4 give
     0000 1010 0000 0000 0000 0000 0000 0000
     D. 1010 0000 0000 0000 0000 0000 0000 0000 >>> 4 give
     1111 1010 0000 0000 0000 0000 0000 0000
     56. Give following fragment.
     Outer: for(int i=0; i<3; i )
     inner:for(int j=0;j<3;j ){
     If(j>1)break outer;
     System.out.println(j ”and” i);
     }
     Which will be output?
     A. 0 and 0 B. 0 and 1 C. 0 and 2 D. 0 and 3
     E. 1 and 0 F. 1 and 1 G. 1 and 2 H. 1 and 3
     I. 2 and 0 J. 2 and 1 K. 2 and 2 L. 2 and 3
     57. Examine the following code which includes an inner class:
     public final class Test4 implements A{
     class Inner{
     void test(){
     if (Test4.this.flag);{
     sample();
     }
     }
     private boolean flag=false;
     }
     public void sample(){
     System.out.println(“Sample”);
     }
     public Test4(){
     (new Inner()).test();
     }
     public static void main(String args[]){
     new Test4();
     }
     }
     What is the result:
     A.Print out “Sample”
     B.Program produces no output but termiantes correctly.
     C. Program does not terminate.
     D.The program will not compile
     58. What is written to the standard output given the following statement:
     System.out.println(4|7);
     Select the right answer:
     A.4
     B.5
     C.6
     D.7
     E.0
     59. Look the inheritance relation:
     person
    |
    ----------------
    | |
    man woman
     In a source of java have the following line:
     person p=new man();
     What statement are corrected?
     A. The expression is illegal.
     B. Compile corrected but running wrong.
     C. The expression is legal.
     D. Will construct a person?s object.
     60. Look the inheritance relation:
     person
    |
    ----------------
    | |
    man woman
     In a source of java have the following line:
     woman w=new man():
     What statement are corrected?
     A. The expression is illegal.
     B. Compile corrected but running wrong.
     C. The expression is legal.
     D. Will construct a woman object.  61. Which can NOT be used in declaring or declaring and initializing an automatic (method local) variable?
     A. final
     B. static
     C. expressions
     D. Constants of non-primitive type
     E. initialized arrays (such as “ {“Hello”,”Good bye”}”).
     62. Given the following incomplete method:
     1) public void method(){
     2)
     3) if (someTestFails()){
     4)
     5) }
     6)
     7) }
     You want to make this method throw an IOException if,and only if,the method someTestFails() returns a value of true.
     Which changes achieve this?
     A. Add at line 2:IOException e;
     B. Add at line 4:throw e;
     C. Add at line 4:throw new IOException();
     D. Add at line 6:throw new IOException();
     E. Modify the method declaration to indicate that an object of type Exception might be thrown.
     63. Given the following definition:
     String s = null;
     Which code fragments cause an object of type NullPointerException to be thrown?
     A. if((s!=null)&(s.length()>0))
     B. if((s!=null)&&(s.length()>0))
     C. if((s==null)|(s.length()==0))
     D. if((s==null)||(s.length()==0))
     64. The following is a program
     1) class Exsuper{
     2) String name;
     3) String nick_name;
     4)
     5) public ExSuper(String s,String t){
     6) name = s;
     7) nick_name = t;
     8) }
     9)
     10) public string toString(){
     11) return name;
     12) }
     13) }
     14)
     15) public class Example extends ExSuper{
     16)
     17) public Example(String s,String t){
     18) super(s,t);
     19) }
     20)
     21) public String to String(){
     22) return name ”a.k.a” nick_name;
     23) }
     24)
     25) public static void main(String args[]){
     26) ExSuper a = new ExSuper(“First”,”1st”);
     27) ExSuper b = new Example(“Second”,”2nd”);
     28)
     29) System.out.println(“a is” a.toString());
     30) System.out.println(“b is” b.toString());
     31) }
     32) }  What happens when the user attempts to compile and run this program?
     A. A Compiler error occurs at line 21
     B. An object of type ClassCastException is thrown at line 27
     C.The following output:
     a is First
     b is second
     D. The following output:
     a is First
     b is Secong a.k.a 2nd
     F. The following output:
     a is First a.k.a 1st
     b is Second a.k.a 2nd
     65. Which statements are true about Listeners?
     A. At most one listener can be added to any simple Component.
     B. The return value from a listener is used to control the invocation of other listener
     C. If multiple listeners are added to a single component, they must all be made friends to each other
     D. If multiple listeners are added to single component, the order of invocation of the listener is not specified.
     E. In the AWT, listener methods generally take an argument, which is an instance of some subclass of java.awt.AWTEvent class.
    答案及詳細(xì)分析:
    51。A、B
    注意,每個(gè)對(duì)象變量在未初始化前都為“null”,并不為“空”。當(dāng)為“空”時(shí),它已經(jīng)被分配具體內(nèi)存空間了,與“null”有本質(zhì)的區(qū)別。
    52。D
    菜單控件只能添加到叫做菜單容器的特殊對(duì)象中,而且布局管理器對(duì)菜單控件不起任何作用。
    53。C
    事件監(jiān)聽器方法就是句柄方法,所有句柄方法的訪問權(quán)限都是public,返回值類型都是void。
    54。MouseEvent
    此題是考試中常見的題型。一般來說,句柄方法的參數(shù)類型與監(jiān)聽器類型是匹配的,只有監(jiān)聽器MouseMotionListener的句柄方法的參數(shù)類型是MouseEvent,與相應(yīng)監(jiān)聽器類型名稱不匹配。
    55。B、C
    “>>” 是帶符號(hào)右移,高位是“1”則補(bǔ)“1”,否則補(bǔ)“0”;“>>>”是無符號(hào)右移,又叫補(bǔ)零右移,不論高位是什么,都是補(bǔ)“0”。
    56。A、E
    注意標(biāo)號(hào)的使用。另外,break表示跳出本語句塊的執(zhí)行,continue繼續(xù)本塊的執(zhí)行。
    57。A
    回答此題時(shí),要仔細(xì)閱讀程序,注意到語句“if(Test4.this.flag);”有一分號(hào),這是沒有執(zhí)行語句的條件語句,所以“sample()”方法總是被調(diào)用。
    58。D
    “|”是按位或運(yùn)算符,先將4和7轉(zhuǎn)為二進(jìn)制數(shù)。轉(zhuǎn)換后就是計(jì)算“100|111”,所以得到結(jié)果是“111”,轉(zhuǎn)為十進(jìn)制整形數(shù)是7。此題提醒考生注意,要熟悉各種運(yùn)算符號(hào)的含義。
    59。C
    這是多態(tài)性的定義方式,p是父類引用指向子類對(duì)象。此時(shí),編譯器認(rèn)為p是一個(gè)person,而不是man ,所以p只能實(shí)現(xiàn)父類的功能。但是當(dāng)p調(diào)用被覆蓋方法時(shí),是指向子類中的該方法。
    60.A
    多態(tài)性的定義允許父類引用指向子類對(duì)象,但是不允許兩個(gè)平等的子類有這樣的操作。所以該表達(dá)式是不合法的。
    61.B
    自動(dòng)變量前不能用“static”修飾。
    以下定義都是允許的:
    final Date d = new Date();
    String [] s = {“Hello”,”abc”};
    int i = x 4;
    所以只有B選項(xiàng)是正確。
    62.C、E
    所有自定義異常,在方法體中拋出了,就必須在方法聲明中拋出。所以除了C選項(xiàng)外,E也必須入選。
    63.A、C
    邏輯運(yùn)算符“&&”、“||”,在運(yùn)算中有“短路”行為:例如 A&&B,如果A的值為false,則直接將整個(gè)表達(dá)式的值置為false,對(duì)B的值不加考察。而運(yùn)算符“&”、“|”就沒有這種行為。所以在選項(xiàng)A、C中,“s.length()”會(huì)導(dǎo)致拋出空指針異常。
    64.D
    源程序的第27行,是多態(tài)性的定義。對(duì)象b調(diào)用被覆蓋方法時(shí)是調(diào)用子類中的該方法。
    65.D、E
    一個(gè)控件可以注冊(cè)多個(gè)監(jiān)聽器,并且事件的響應(yīng)沒有特定的順序。句柄方法的參數(shù)是類AWTEvent類的子類。