1.In Java a variable may contain
A a value or a reference
B a package
C a method
D a class
E any of the above
在JAVA中變數只能包含一個值或一個引用。所以應該選a的。
2.If two variables contain aliases of the same object then
A the object may be modified using either alias
B the object cannot be modified unless there‘s but a single reference to it
C a third alias is created if/when the object is modified
D the object will become an "orphan" if both variables are set to null
E answers A and D are correct
對象可以使用別名進行修改,如果兩個變數都設定為null,那麼對象將變成一個“孤兒”。
3.Which properties are true of String objects?
A Their lengths never change
B The shortest string has zero length
C Individual characters within a String may be changed using the replace method
D The index of the first character in a string is one
E Only A and B are true
他們的長度永遠不會改變,最短的字串長度為零。字串是不可變的。這意味著, 一旦建立了字串對象, 就不能更改它。因此, 字串的長度在建立後不會更改。最短長度字串為 "", 引號之間沒有字元, 因此長度為零。
4.What happens if you attempt to use a variable before it has been initialized?
A A syntax error may be generated by the compiler
B A runtime error may occur during execution
C A "garbage" or "uninitialized" value will be used in the computation
D A value of zero is used if a variable has not been initialized
E Answers A and B are correct
編譯器多次能夠檢測到未初始設定變數的嘗試使用, 在這種情況下會產生語法錯誤。如果編譯器使用轉義檢測, 則在使用時會發生執行階段錯誤。
5.What is the function of the dot operator?
A It serves to separate the integer portion from the fractional portion of a floating point number
B It allows one to access the data within an object when given a reference to the object
C It allows one to invoke a method within an object when given a reference to the object
D It is used to terminate commands (much as a period terminates a sentence in English)
E Both B and C are correct
點算符的功能為:它允許在給定對象的引用時訪問對象中的資料,當給定對象的引用時,它允許在對象中調用方法。所以這道題應該選e的。
6.Unlike the String class where you must pass a message to an object (instance) of the class, as in x.length( ), in order to use the Math class, you pass messages directly to the class name, as in Math.abs( ) or Math.sqrt( ).
A .true
B .false
數學類使用被稱為靜態方法 (或類方法) 的方法, 通過將訊息直接傳遞到類名本身而不是類的對象來調用。
7.Which of the following will yield a pseudorandom number in the range [ -5, +5 ) given the following:
Random gen = new Random( );
A . gen.nextFloat( ) * 5
B . gen.nextFloat( ) * 10 - 5
C . gen.nextFloat( ) * 5 - 10
D . gen.nextInt( ) * 10 - 5
E . gen.nextInt(10) - 5
gen.nextInt(10) - 5 所得到的結果是-5,-4,-3,-2,-1,0,1,2,3,4,並不是題目中所要求的,它得到的只是一些數而不是一個取值範圍。而nextFloat則是在範圍[0,1)中產生偽隨機數字;乘以10的收益率在0到10之間,再減去5,得到結果。
8.Consider the following two lines of code. What can you say about s1 and s2?
String s1 = "testing" + "123";
String s2 = new String("testing 123");
A . s1 and s2 are both references to the same String objects
B . the line declaring s2 is legal Java; the line declaring s1 will produce a syntax error
C . s1 and s2 are both references to different String objects
D . s1 and s2 will compare "equal"
E . none of the above
這兩個聲明都是合法的Java。s1是一個字串引用,它被初始化為字串“testing123”。s2是一個字串引用,它被初始化為字串“測試123”。注意“測試”和“123”之間的空格。所以這兩個字串不相等。
9.An "alias"(別名) is when
A . two different reference variables refer to the same physical object
B . two different numeric variables refer to the same physical object
C . two different numeric variables contain identical values
D . two variables have the same names
E . none of the above
當有兩個或多個對同一物理對象的引用時,就會出現“別名”,這樣,通過遵循任一引用,就可以讀/寫/修改對象
10.The String class‘ compareTo method
A . compares two string in a case-independent manner(獨立的方式)
B . yields (收益率)true or false
C . yields 0 if the two strings are identical
D . returns 1 if the first string comes lexically before the second string
E . none of the above
如果兩個字串是完全一致的,那麼它的值為0。
11.The advantages of the DecimalFormat class compared with the NumberFormat class include
A precise control over the number of digits to be displayed
B control over the presence of a leading zero
C the ability to truncate values rather than to round them
D the ability to display a % automatically at the beginning of the display
E only A and B
偽隨機數產生器相對於Math.random的優勢在於:可以建立幾個隨機數產生器,可以在一個範圍內產生隨機的int,floats和ints。所以應該包括A與B。
12.If you need to import not only the top-level of a package, but all its secondary levels as well, you should write: import package..;
A true
B false
如果您不僅需要匯入包的頂層, 而且還要輸入所有的輔助層級, 則應編寫: 匯入包. ;(false);匯入包.
13.You may use the String replace( ) method to remove characters from a String.
A true
B false
replace()方法僅用其他單個字元替換單個字元。replace()方法不會將字元添加或刪除字串;字串長度將保持不變
14.All the methods in the Math class are declared to be static.
A true
B false
數學類方法被設計成在算術運算式中通常有用,因此不需要任何執行個體來使用它們。這是通過確保所有的數學方法都是靜態來實現的。
15.The advantage(s) of the Random class‘ pseudo-random number generators, compared to the Math.random method, is that
A . you may create several random number generators
B . the generators in Random are more efficient than the one in Math.random
C . you can generate random ints, floats, and ints within a range
D . you can initialize and reinitialize Random generators
E . all but answer B
所有隨機數字產生器的效率是一樣的。隨機產生器優於數學的優點。隨機包含所有其他屬性。
16.The advantages of the DecimalFormat class compared with the NumberFormat class include
A . precise control over the number of digits to be displayed
B . control over the presence of a leading zero
C . the ability to truncate values rather than to round them
D . the ability to display a % automatically at the beginning of the display
E . only A and B
通過一個或多個數學方法,截斷在程式員的手中“%”符號會出現在顯示器的末端,而不是開始。