《SCJP考試題集》word版_第1頁
《SCJP考試題集》word版_第2頁
《SCJP考試題集》word版_第3頁
《SCJP考試題集》word版_第4頁
《SCJP考試題集》word版_第5頁
已閱讀5頁,還剩76頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、1. Which of the following range of short is correct? A. -27 - 27-1 B. 0 - 216-1 C. ?215 - 215-1 D. ?231 - 231-1 翻譯 下面哪些是short型的取值范圍。 答案 C 解析 短整型的數(shù)據(jù)類型的長度是16 bits,有符號。另外需要說明的是java中所有的整(Integral)數(shù)(包括byte,short,int,long)全是有符號的。 2. Which declarations of identifiers are legal? A. $persons B. TwoUsers C. *

2、point D. this E. _endline 翻譯 下面哪些是合法的標(biāo)識符。 答案 A,B,E 解析 Java的標(biāo)識符可以以一個Unicode字符,下滑線(_),美元符($)開始,后續(xù)字符可以是前面的符號和數(shù)字,沒有長度限制,大小寫敏感,不能是保留字。 3. Which statement of assigning a long type variable to a hexadecimal value is correct? A. long number = 345L; B. long number = 0345; C. long number = 0345L; D. long numb

3、er = 0 x345L 翻譯 哪些是將一個十六進(jìn)制值賦值給一個long型變量。 答案 D 解析 十六進(jìn)制數(shù)以0 x開頭,long型數(shù)以L(大小寫均可,一般使用大寫,因為小寫的l和數(shù)字1不易區(qū)分)。 4.Which of the following fragments might cause errors? A. String s = Gone with the wind; String t = good ; String k = s + t; B. String s = Gone with the wind; String t; t = s3 + one; C. String s = Gon

4、e with the wind; String standard = s.toUpperCase(); D. String s = home directory; String t = s - directory; 翻譯 下面的哪些程序片斷可能導(dǎo)致錯誤。 答案B,D 解析 A:String類型可以直接使用+進(jìn)行連接運算。 B:String是一種Object,而不是簡單的字符數(shù)組,不能使用下標(biāo)運算符取其值的某個元素,錯誤。 C:toUpperCase()方法是String對象的一個方法,作用是將字符串的內(nèi)容全部轉(zhuǎn)換為大寫并返回轉(zhuǎn)換后的結(jié)果(String類型)。 D:String類型不能進(jìn)行減(-

5、)運算,錯誤。5. Which are syntactically valid statement at/ point x? class Person private int a; public int change(int m) return m; public class Teacher extends Person public int b; public static void main(String arg) Person p = new Person(); Teacher t = new Teacher(); int i; / point x A. i = m; B. i = b;

6、 C. i = p.a; D. i = p.change(30); E. i = t.b. 翻譯 在/ point x處的哪些申明是句法上合法的。 答案D,E 解析 A:m沒有被申明過,不能使用。 B:雖然b是類Teacher的public成員變量,但是在靜態(tài)方法中不能使用類中的非靜態(tài)成員。 C:a是類Person的private成員,在類外不能直接引用。 D:change(int m)方法是public方法,并且返回一個int型值,可以通過類的實例變量p引用并賦值給一個int型變量。 E:b是類Teacher的public成員變量,且是int型,可以通過類的實例變量t引用并賦值給一個int型

7、變量。 6. Which layout manager is used when the frame is resized the buttonss position in the Frame might be changed? A. BorderLayout B. FlowLayout C. CardLayout D. GridLayout 翻譯 當(dāng)Frame的大小被改變時Frame中的按鈕的位置可能被改變時使用的哪一個布局管理器。 答案 B 解析 A:該布局管理器將容器劃分為五個部分,容器大小的改變不會影響其中的組件的位置而是影響他們的大小。 B:該布局管理器根據(jù)放入其中的組件的最合適大小

8、調(diào)整組件的位置,根據(jù)組件放入的順序安排,一行不能容納時放入下一行,因此容器的大小改變可能改變組件的位置。 C:該布局管理器顯示放入該容器的當(dāng)前頁中的組件,一次顯示一個,容器大小的改變不能影響其中組件的位置。 D:該布局管理器將容器劃分為固定的網(wǎng)格,組件加入后占據(jù)一個單元,各組件的相對位置不會因為容器的大小變化而變化,改變的只是組件的大小。7. Given the following code fragment: 1) public void create() 2) Vector myVect; 3) myVect = new Vector(); 4) Which of the followin

9、g statements are true? A. The declaration on line 2 does not allocate memory space for the variable myVect. B. The declaration on line 2 allocates memory space for a reference to a Vector object. C. The statement on line 2 creates an object of class Vector. D. The statement on line 3 creates an obje

10、ct of class Vector. E. The statement on line 3 allocates memory space for an object of class Vector 翻譯 給出下面的代碼片斷。下面的哪些陳述為true(真)? A. 第二行的聲明不會為變量myVect分配內(nèi)存空間。 B. 第二行的聲明分配一個到Vector對象的引用的內(nèi)存空間。 C. 第二行語句創(chuàng)建一個Vector類對象。 D. 第三行語句創(chuàng)建一個Vector類對象。 E. 第三行語句為一個Vector類對象分配內(nèi)存空間。 答案A,D,E 解析SL-275中指出:要為一個新對象分配空間必須執(zhí)行n

11、ew Xxx()調(diào)用,new調(diào)用執(zhí)行以下 的操作: 1 為新對象分配空間并將其成員初始化為0或者null。 2 執(zhí)行類體中的初始化。(例如在類中有一個成員聲明int a=10;在第一步后a=0 ,執(zhí)行到第二步后a=10) 3 執(zhí)行構(gòu)造函數(shù)。 4 變量被分配為一個到內(nèi)存堆中的新對象的引用。8. Which of the following answer is correct to express the value 8 in octal number? A. 010 B. 0 x10 C. 08 D. 0 x8 翻譯 下面的哪些答案可以用以表示八進(jìn)制值8。 答案 A 解析 八進(jìn)制值以0開頭,以0

12、 x開頭的為十六進(jìn)制值,八進(jìn)制中不能出現(xiàn)數(shù)字8,最大只有7。 9. Which are not Java keywords? A. TRUE B. sizeof C. const D. super E. void 翻譯 哪些不是Java關(guān)鍵字。 答案A,B 解析 A: 不是,Java中有true,但是這也不是關(guān)鍵字而是字面量(literal)。 B: 不是,Java中不需要這個操作符,所有的類型(原始類型)的大小都是固定的。 C、D、E都是,需要說明的是const是java中未被使用的關(guān)鍵字。10. Which of the following statements are true? A.

13、The equals() method determines if reference values refer to the same object. B. The = operator determines if the contents and type of two separate objects match. C. The equals() method returns true only when the contents of two objects match. D. The class File overrides equals() to return true if th

14、e contents and type of two separate objects match. 翻譯 下面的哪些敘述為真。A. equals()方法判定引用值是否指向同一對象。 B. = 操作符判定兩個分立的對象的內(nèi)容和類型是否一致。 C. equals()方法只有在兩個對象的內(nèi)容一致時返回true。 D. 類File重寫方法equals()在兩個分立的對象的內(nèi)容和類型一致時返回true。 答案A,D 解析 嚴(yán)格來說這個問題的答案是不確定的,因為equals()方法是可以被重載的,但是按照java語言的本意來說:如果沒有重寫(override)新類的 equals(),則該方法和 = 操

15、作符一樣在兩個變量指向同一對象時返回真,但是java推薦的是使用equals()方法來判斷兩個對象的內(nèi)容是否一樣,就像String類的 equals()方法所做的那樣:判定兩個String對象的內(nèi)容是否相同,而=操作符返回true的唯一條件是兩個變量指向同一對象。從這個意義上來 說選擇給定的答案。從更嚴(yán)格的意義來說正確答案應(yīng)該只有d。11. Which statements about inheritance are true? A. In Java programming language only allows single inheritance. B. In Java programm

16、ing language allows a class to implement only one interface. C. In Java programming language a class cannot extend a class and implement a interface together. D. In Java programming language single inheritance makes code more reliable. 翻譯 下面關(guān)于繼承的哪些敘述是正確的。 A 在java中只允許單一繼承。 B 在java中一個類只能實現(xiàn)一個接口。 C 在jav

17、a中一個類不能同時繼承一個類和實現(xiàn)一個接口。 D java的單一繼承使代碼更可靠。 答案A,D 解析 在java中一個類只能有一個直接父類,但是可以實現(xiàn)多個接口,在繼承的同時可以實現(xiàn)接口,之所以取消多繼承的原因是多繼承使得代碼產(chǎn)生很多問題,而使用單一繼承則可以使代碼更可靠。 12. 1) class Person 2) public void printValue(int i, int j) /*/ 3) public void printValue(int i)/*.*/ 4) 5) public class Teacher extends Person 6) public void pri

18、ntValue() /*.*/ 7) public void printValue(int i) /*.*/ 8) public static void main(String args) 9) Person t = new Teacher(); 10) t.printValue(10); 11) 12) Which method will the statement on line 10 call? A. on line 2 B. on line 3 C. on line 6 D. on line 7 翻譯 第十行的聲明將調(diào)用哪些方法。 答案 D 解析 變量t是一個Person對象,但是它是

19、用Teacher實例化的,這個問題涉及到j(luò)ava的編譯時多態(tài)和運行時多態(tài)的問題,就編譯時多態(tài)來說,t實際上 是一個Person類,這涉及到類型的自動轉(zhuǎn)換(將一個子類的實例賦值給一個父類的變量是不用進(jìn)行強(qiáng)制類型轉(zhuǎn)換,反之則需要進(jìn)行強(qiáng)制類型轉(zhuǎn)換,而且被賦值 的變量實際上應(yīng)該是一個子類的對象),如果對t調(diào)用了子類中新增的方法則造成編譯時錯誤編譯將不能通過,而在運行時,運行時系統(tǒng)將根據(jù)t實際指向的類型調(diào) 用對應(yīng)的方法,對于本例來說,t.print(10)將調(diào)用t實際指向的Teacher類的對應(yīng)方法。在java中,可以用一個子類的實例實例化父類的一 個變量,而變量在編譯時是一個父類實例,在運行時可能是一

20、個子類實例。13. Which are not Java primitive types? A. short B. Boolean C. unit D. float 翻譯 下面哪些不是java的原始數(shù)據(jù)類型。 答案B,C 解析 Java的原始數(shù)據(jù)類型一共就八個,分別是:byte,short,int,long,boolean,char,float,double。注意這些是 大小寫敏感的,而Boolean是booelan的封裝類(wrapper class)。 14. Use the operators , which statements are true? A. 0000 0100 0000

21、0000 0000 0000 0000 00005 gives 1000 0000 0000 0000 0000 0000 0000 0000 B. 0000 0100 0000 0000 0000 0000 0000 00005 gives 1111 1110 0000 0000 0000 0000 0000 0000 D. 1100 0000 0000 0000 0000 0000 0000 00005 gives 0000 0110 0000 0000 0000 0000 0000 0000 翻譯 使用操作符的哪些陳述是對的。 答案A,C 解析 Java的移位操作符一共有三種,分別是”,

22、”,” 32的結(jié)果是a而不是0,同理,對long型數(shù)是對右操作數(shù)取64的模,a64=a;還有一點需要注意的是移位操作符” ”只對int型和long型有效,對byte或者short的操作將導(dǎo)致自動類型轉(zhuǎn)換,而且是帶符號的。 15. Which of the following range of int is correct? A. -27 - 27-1 B. 0 - 232-1 C. ?215 - 215-1 D. ?231 - 231-1 翻譯 int的取值范圍是哪個。 答案 D 解析 int型是32位的。參看第一題的論述。 16. Which keyword should be used t

23、o enable interaction with the lock of an object? The flag allows exclusive access to that object. A. transient B. synchronized C. serialize D. static 翻譯 下面的哪些關(guān)鍵字通常用來對對象的加鎖,該標(biāo)記使得對對象的訪問是排他的 答案 B 解析 由于java是多線程的語言,多個線程可以”同時”訪問同一數(shù)據(jù)區(qū),而在處理某些數(shù)據(jù)時不希望其它的線程修改那些數(shù)據(jù)的值或者某些操作是不可打斷的,要做到這個,可以使用synchronized關(guān)鍵字聲明這一點。17.

24、 Which is the return type of the method main()? A. int B. void C. boolean D. static 翻譯 main()方法的返回類型是什么? 答案 B 解析 在java中,程序運行的入口就是main()方法,它必須是這樣的形式:public static void main(String args)。但是嚴(yán)格來講這個題目的答案還可以加上a和c,因為并沒有限定是程序入口的main()方法,而main()方法是可以重載的。一般意義 上的main()當(dāng)然就是指我們剛開始所說的main()方法了。18. Given the follo

25、wing code: if (x0) System.out.println(first); else if (x-3) System.out.println(second); else System.out.println(third); Which range of x value would print the string second? A. x 0 B. x -3 C. x = -3 D. x -3 翻譯 給出下面的代碼: x的取值在什么范圍內(nèi)時將打印字符串second。 答案 D 解析 x0時打印first,x-3&x=0時打印second,x 10 ) public static

26、 void main(String arg) int i=10; Test t= new Test(); t.printValue(i); Which will be output? A. The value is 8 B. The value is 9 C. The value is 10 D. The value is 11 (c) 題目:給出下面的代碼: 輸出將是什么? 此題考察的是do while循環(huán)和 - 操作符的知識,dowhile最少被執(zhí)行一次,在執(zhí)行完do中的內(nèi)容后判斷while中的條件是否為true,如果為true的話就再執(zhí)行do中的內(nèi) 容,然后再進(jìn)行判斷,以此類推直到whi

27、le的判斷為false時退出循環(huán)執(zhí)行循環(huán)后面的內(nèi)容,而?操作符的規(guī)則是在變量右邊的 - 將先進(jìn)行運算,然后才是使變量的值減一,而在變量左邊的是先將變量的值減一再運算。 26、Which of the following statements about declaration are true? A. Declaration of primitive types such as boolean, byte and so on does not allocate memory space for the variable. B. Declaration of primitive types su

28、ch as boolean, byte and so on allocates memory space for the variable. C. Declaration of nonprimitive types such as String, Vector and so on does not allocate memory space for the object. D. Declaration of nonprimitive types such as String, Vector ans so on allocates memory space for the object. (ad

29、) 題目:下面的有關(guān)聲明的哪些敘述是對的。 A. 對原始數(shù)據(jù)類型例如boolean,byte的變量的聲明不會為該變量分配內(nèi)存空間。 B. 對原始數(shù)據(jù)類型例如boolean,byte的變量的聲明將為之分配內(nèi)存空間。 C. 非原始數(shù)據(jù)類型例如String,Vector的變量的聲明不會為該對象分配內(nèi)存。 D. 非原始數(shù)據(jù)類型例如String,Vector的變量的聲明會為該對象分配內(nèi)存。 對原始數(shù)據(jù)類型的變量的聲明將為之分配內(nèi)存并賦予一個缺省值,參見23題的敘述,而非原始數(shù)據(jù)類型的變量必須用new Xxxx()分配內(nèi)存及初始化。但是嚴(yán)格來講此題的答案有待確定,因為只有原始類型的實例變量和類變量的聲明在

30、類對象被創(chuàng)建/類被加載時完成內(nèi)存的自動分 配,而原始類型的局部變量必須顯式初始化,從這點來看原始類型的局部變量沒有被自動分配內(nèi)存,SL275中只提出了非原始數(shù)據(jù)類型的變量必須使用new Xxxx()完成內(nèi)存的分配而沒有指出原始數(shù)據(jù)類型的變量是否在聲明時即自動進(jìn)行內(nèi)存分配,而從局部變量不能在顯式初始化前使用這點來看在聲明時沒有進(jìn)行 內(nèi)存分配。因此答案a的正確性還有待官方的確定。27、In the Java API documentation which sections are included in a class document? A. The description of the cla

31、ss and its purpose B. A list of methods in its super class C. A list of member variable D. The class hierarchy (acd) 題目:在Java API文檔中下面的哪些部分被包括在內(nèi) A. 類及用途的描述 B. 父類的方法的列表 C. 成員變量的列表 D. 類層次 類文檔的內(nèi)容主要是:類層次、類及用途描述、成員變量列表、構(gòu)造方法列表、成員方法列表、從類層次上繼承的方法列表、成員變量的詳細(xì)說明、構(gòu)造方法詳細(xì)說明、成員方法詳細(xì)說明。 28、Given the following code: 1

32、) public void modify() 2) int i, j, k; 3) i = 100; 4) while ( i 0 ) 5) j = i * 2; 6) System.out.println ( The value of j is + j ); 7) k = k + 1; 8) i-; 9) 10) Which line might cause an error during compilation? A. line 4 B. line 6 C. line 7 D. line 8 (c) 題目:給出下面的代碼: 哪些行在編譯時可能產(chǎn)生錯誤。 這個問題在前面有關(guān)變量的類型及其作用

33、域的問題中討論過,局部變量在使用前必須顯式初始化,而代碼中的變量k在使用前沒有。 29、Which of the following statements about variables and scope are true? A. Local variables defined inside a method are destroyed when the method is exited. B. Local variables are also called automatic variables. C. Variables defined outside a method are crea

34、ted when the object is constructed. D. A method parameter variable continues to exist for as long as the object is needed in which the method is defined. (abc) 題目:下面有關(guān)變量及其作用域的陳述哪些是對的。 A. 在方法里面定義的局部變量在方法退出的時候被撤銷。 B. 局部變量也叫自動變量。 C. 在方法外面定義的變量(譯注:即實例變量)在對象被構(gòu)造時創(chuàng)建。 D. 在方法中定義的方法的參變量只要該對象被需要就一直存在。 本題還是討論變量

35、的類型及作用域,參看前面的敘述。 30、 A class design requires that a member variable cannot be accessible directly outside the class. Which modifier should be used to obtain the access control? A. public B. no modifier C. protected D. private (d) 題目:類的設(shè)計要求它的某個成員變量不能被外部類直接訪問。應(yīng)該使用下面的哪些修飾符獲得需要的訪問控制。 這個在前面也有敘述,java有四種訪問

36、類型,分別為:public,protected,default,private,其中public變量可以被 所有的外部類訪問,而pretected的可以被同一個包及該類的子類訪問,default即沒有任何修飾符的變量可以被同一個包中的類訪問,而 private變量只能在被該類內(nèi)部被訪問。題目中的外部類應(yīng)該理解為除該類自身的所有其它類,因此只有使用private可以達(dá)到要求。31Given the following code fragment: 1) String str = null; 2) if (str != null) & (str.length() 10) 3) System.out

37、.println(more than 10); 4) 5) else if (str != null) & (str.length() 5) 6) System.out.println(less than 5); 7) 8) else System.out.println(end); Which line will cause error? A. line 1 B. line 2 C. line 5 D. line 8 (c) 題目:給出下面的代碼片斷: 哪些行將導(dǎo)致錯誤。 此題需要將代碼仔細(xì)看清楚,查詢沒有邏輯錯誤,if else的使用沒有問題,也沒有拼寫錯誤,錯誤在于第5行的“與”操作符的

38、使用,邏輯操作符(logical operator)的“與”應(yīng)該是&,而在執(zhí)行“與”操作的時候,如果第一個條件為false,那么第二個條件判斷運算是不做的,但是 這里是位邏輯操作符(bitwise logical operator)的“與”,在進(jìn)行這個運算時,無論第一個條件的結(jié)果是什么都會執(zhí)行第二個的運算,因此,假設(shè)str=null,那么第5句的 str.length()就會導(dǎo)致NullPointerException,因此本題的錯誤在于此。 32、Which statements about Java code security are true? A. The bytecode verif

39、ier loads all classes needed for the execution of a program. B. Executing code is performed by the runtime interpreter. C. At runtime the bytecodes are loaded, checked and run in an interpreter. D. The class loader adds security by separating the namespaces for the classes of the local file system f

40、rom those imported from network sources. (bcd) 題目:下面有關(guān)java代碼安全性的敘述哪些是對的。 A. 字節(jié)碼校驗器加載查詢執(zhí)行需要的所有類。 B. 運行時解釋器執(zhí)行代碼。 C. 在運行時,字節(jié)碼被加載,驗證然后在解釋器里面運行。 D. 類加載器通過分離本機(jī)文件系統(tǒng)的類和從網(wǎng)絡(luò)導(dǎo)入的類增加安全性。 SL275中描述的Java程序運行的過程是這樣的:類加載器(class loader)加載程序運行所需要的所有類,它通過區(qū)分本機(jī)文件系統(tǒng)的類和網(wǎng)絡(luò)系統(tǒng)導(dǎo)入的類增加安全性,這可以限制任何的特洛伊木馬程序,因為本機(jī)類總是 先被加載,一旦所有的類被加載完,執(zhí)

41、行文件的內(nèi)存劃分就固定了,在這個時候特定的內(nèi)存地址被分配給對應(yīng)的符號引用,查找表(lookuo table)也被建立,由于內(nèi)存劃分發(fā)生在運行時,解釋器在受限制的代碼區(qū)增加保護(hù)防止未授權(quán)的訪問;然后字節(jié)碼校驗器(byte code verifier)進(jìn)行校驗,主要執(zhí)行下面的檢查:類符合JVM規(guī)范的類文件格式,沒有違反訪問限制,代碼沒有造成堆棧的上溢或者下溢,所有操作代碼的參 數(shù)類型都是正確的,沒有非法的數(shù)據(jù)類型轉(zhuǎn)換(例如將整型數(shù)轉(zhuǎn)換成對象類型)發(fā)生;校驗通過的字節(jié)碼被解釋器(interpreter)執(zhí)行,解釋器在必要 時通過運行時系統(tǒng)執(zhí)行對底層硬件的合適調(diào)用。后三個答案是SL275中的原話。 3

42、3、Given the following code: public class Person static int arr = new int10; public static void main(String a) System.out.println(arr1;) Which statement is correct? A. When compilation some error will occur. B. It is correct when compilation but will cause error when running. C. The output is zero. D

43、. The output is null. (c) 題目:給出下面的代碼: 那個敘述是對的。 A. 編譯時將發(fā)生錯誤。 B. 編譯時正確但是運行時出錯。 C. 輸出為0。 D. 輸出為null int型數(shù)組是類對象,它在類被加載時完成初始化,在前面題目中已經(jīng)有敘述,由于是原始數(shù)據(jù)類型int,其初始值為0。34、Given the following code: public class Person int arr = new int10; public static void main(String a) System.out.println(arr1); Which statement i

44、s correct? A. When compilation some error will occur. B. It is correct when compilation but will cause error when running. C. The output is zero. D. The output is null. (a) 給出下面的代碼: 哪些敘述是對的。 A. 編譯時出錯。 B. 編譯時正確而運行時出錯。 C. 輸出0。 D. 輸出null。 實例變量在類的一個實例構(gòu)造時完成初始化,而且在類的靜態(tài)方法中不能直接訪問類的非靜態(tài)成員而只能訪問類成員(像上題中一樣),類的普通

45、方法可以訪問類的 所有成員和方法,而靜態(tài)方法只能訪問類的靜態(tài)成員和方法,因為靜態(tài)方法屬于類,而普通方法及成員變量屬于類的實例,類方法(靜態(tài)方法)不能使用屬于某個不 確定的類的實例的方法和變量,在靜態(tài)方法里面沒有隱含的this,而普通方法有。 35、public class Parent public int addValue( int a, int b) int s; s = a+b; return s; class Child extends Parent Which methods can be added into class Child? A. int addValue( int a,

46、 int b )/ do something. B. public void addValue ()/ do something. C. public int addValue( int a )/ do something. D. public int addValue( int a, int b )throws MyException /do something. (bc) 題目:哪些方法可以加入類Child中。 此題涉及方法重載(overload),方法重寫(override)以及類派生時方法重寫的規(guī)則。方法重載的規(guī)則是:一、參數(shù)列表必須不同,個數(shù)的不同 完全可以,如果個數(shù)相同則參數(shù)類型的

47、不同不能引起歧意,例如int 和long,float和double就不能作為唯一的類型不同;二、返回值可以不同,但是不能是重載時唯一的不同點(這點和c+中不同,c+中返回 類型必須一致)。方法重寫發(fā)生在類繼承時,子類可以重寫一個父類中已有的方法,必須在返回類型和參數(shù)列表一樣時才能說是重寫,否則就是重載,java中方 法重寫的一個重要而且容易被忽略的規(guī)則是重寫的方法的訪問權(quán)限不能比被重寫的方法的訪問權(quán)限低!重寫的另一個規(guī)則是重寫的方法不能比被重寫的方法拋棄 (throws)更多種類的異常,其拋棄的異常只能少,或者是其子類,不能以拋棄異常的個數(shù)來判斷種類,而應(yīng)該是異常類層次結(jié)果上的種類。此題中答案

48、a的 錯誤就是重寫的訪問權(quán)限比被重寫的方法的低,而b,c都屬于重載,d的錯誤在于比被重寫的方法拋棄了更多種類的異常。 36、 A member variable defined in a class can be accessed only by the classes in the same package. Which modifier should be used to obtain the access control? A. private B. no modifier C. public D. protected (b) 題目:一個類中定義的成員變量只能被同一包中的類訪問。下面的哪

49、些修飾符可以獲得需要的訪問控制。 參看前面的題目中的敘述。 37、 A public member vairable called MAX_LENGTH which is int type, the value of the variable remains constant value 100. Use a short statement to define the variable. A. public int MAX_LENGTH=100; B. final int MAX_LENGTH=100; C. final public int MAX_LENGTH=100; D. public

50、 final int MAX_LENGTH=100. (d) 題目:共有成員變量MAX_LENGTH是一個int型值,變量的值保持常數(shù)值100。使用一個短聲明定義這個變量。 Java中共有變量使用public定義,常量變量使用final,另外注意的是修飾符的順序,一個最完整的修飾是public static final int varial_a=100;這個順序不能錯,這和c+中也是不同的。而答案c恰恰錯在修飾符的順序上。38、Which expressions are correct to declare an array of 10 String objects? A. char str;

51、 B. char str; C. String str; D. String str10; (c) 題目:哪些表達(dá)式是聲明一個含有10個String對象的數(shù)組。 嚴(yán)格來說這個題目沒有給出一個正確的答案,唯一比較正確的是c,而完全滿足題目要求的應(yīng)該是:String str=new String10; 注意答案d的形式是不對的,這和c+也是不同的。 39、Which fragments are correct in Java source file? A. package testpackage; public class Test/do something. B. import java.io.

52、*; package testpackage; public class Test/ do something. C. import java.io.*; class Person/ do something. public class Test/ do something. D. import java.io.*; import java.awt.*; public class Test/ do something. (acd) 題目:下面的那個java源文件代碼片斷是對的。 Java中的package語句必須是源文件中除去說明以外的第一條語句,導(dǎo)入包語句可以有幾個,但是必須位于packag

53、e語句之后,其它類定義之前, 一個源文件中可以有幾個類,但最多只能有一個是public的,如果有,則源文件的文件名必須和該類的類名相同。 40: String s= hello; String t = hello; char c = h,e,l,l,o ; Which return true? A. s.equals(t); B. t.equals(c); C. s=t; D. t.equals(new String(hello); E. t=c. (acd) 題目:哪些返回true。 這個在前面第10題的equals()方法和=操作符的討論中論述過。=操作符比較的是操作符兩端的操作數(shù)是否是同

54、一個對象,而String的 equals()方法比較的是兩個String對象的內(nèi)容是否一樣,其參數(shù)是一個String對象時才有可能返回true,其它對象都返回假。需要指出的 是由于s和t并非使用new創(chuàng)建的,他們指向內(nèi)存池中的同一個字符串常量,因此其地址實際上是相同的(這個可以從反編譯一個簡單的測試程序的結(jié)果得到,限 于篇幅不列出測試代碼和反編譯的分析),因此答案c也是正確的。 Question No: 1 Given: 1. public class test ( 2. public static void main (String args) 3. int i = 0 xFFFFFFF1;

55、 4. int j = i; 5. 6. 7. ) What is the decimal value of j at line 5? A. 0 B. 1 C. 14 D. 15 E. An error at line 3 causes compilation to fail. F. An error at line 4 causes compilation to fail. Answer: DQuestion No: 2 Given: Integer i = new Integer (42); Long 1 = new Long (42); Double d = new Double (42

56、.0); Which two expressions evaluate to True? (Choose Two) A. (i =1) B. (i = d) C. (d = 1) D. (i.equals (d) E. (d.equals (i) F. (i.equals (42) Answer: D, E Question No: 3 Exhibit : 1. public class test ( 2. private static int j = 0; 3. 4. private static boolean methodB(int k) ( 5. j += k; 6. return t

57、rue; 6. ) 7. 8. public static void methodA(int i) 9. boolean b: 10. b = i 10 | methodB (4); 11. b = i -j) continue; 6. ) while (i+j) & (i+ =j) 6. i +=j; 7. 8. 9. What is the final value of i? A. 1 B. 2 C. 3 D. 4 E. 5 Answer: B QUESTION NO: 95 Exhibit: 1. public class X 2. public static void main (St

58、ringargs) 3. string s = new string (“Hello”); 4. modify(s); 5. System.out.printIn(s); 6. 7. 8. public static void modify (String s) 9. s += “world!”; 10. 11. What is the result? E. The program runs and prints “Hello” F. An error causes compilation to fail. G. The program runs and prints “Hello world

59、!” H. The program runs but aborts with an exception. Answer: A QUESTION NO: 96 Which two are equivalent? (Choose Two) A. 164 B. 16/2 C. 16*4 D. 162 E. 16/22 F. 162 Answer: D, F QUESTION NO: 97 Exhibit: 1. public class X 2. public static void main (Stringargs) 3. int a = new int 1 4. modify(a); 5. Sy

60、stem.out.printIn(a0); 6. 7. 8. public static void modify (int a) 9. a0 +; 10. 11. What is the result? A. The program runs and prints “0” B. The program runs and prints “1” C. The program runs but aborts with an exception. D. An error “possible undefined variable” at line 4 causes compilation to fail

溫馨提示

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

最新文檔

評論

0/150

提交評論