無論你是個新手,還是程式設計方面的專家,你都會驚異於sun公司j**a的無窮魅力。j**a帶給你的並不僅僅是物件導向、開放、平台無關、易用、安全和「write once, run anywhere」等軟體開發方面的優勢,更重要的一點是,它提供了一種新穎的表達思想的方式,一種全新的思維模式。隨著待解決問題的規模不斷膨脹,j**a徹底的物件導向思想的靈活性就會凸現出來。
毋庸置疑,j**a是你開發大型軟體時最得心應手的利器或是你轉行it的入門首選。
試題分析
例題1:
choose the three valid identifiers from those listed below.
a. idolikethelongnameclass
b. $byte
c. const
d. _ok
e. 3_case
解答:a、b、d
點評:j**a中的標示符必須是字母、美元符($)或下劃線(_)開頭。關鍵字與保留字不能作為標示符。
選項c中的const是j**a的保留字,所以不能作標示符。選項e中的3_case以數字開頭,違反了j**a的規則。
例題2:
how can you force garbage collection of an object?
a. garbage collection cannot be forced
b. call
c. call passing in a reference to the object to be garbage collected.
d. call
e. set all references to the object to new values(null, for example).
解答:a
點評:在j**a中垃圾收集是不能被強迫立即執行的。呼叫或靜態方法不能保證垃圾收集器的立即執行,因為,也許存在著更高優先順序的執行緒。
所以選項b、d不正確。選項c的錯誤在於,方法是不接受引數的。選項e中的方法可以使物件在下次垃圾收集器執行時被收集。
例題3:
consider the following class:
1. public class test
5. void test(string s)
8. 9. public static void main(string args)
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)
b. boolean b=true;
boolean b2=true;
if(b==b2)
c. int i=1;
int j=2;
if(i==1|| j==2)
d.int i=1;
int j=2;
if (i==1 &| j==2)
解答:b, c
點評:選項a錯,因為if語句後需要乙個boolean型別的表示式。邏輯操作有^、&、| 和 &&、||,但是「&|」是非法的,所以選項d不正確。
例題5:
1. int a1 =2;
2. int a2 = 2;
3. int b = (++a1) * 2 – (a2--) * 3;
4. int c = (a1--) * 3 + (++a2) * 2;
what is the result?
a. b = 0 and c = 13
b. b = 0 and c = 12
c. b = 3 and c = 12
d. b = 3 and c = 13
解答:a
點評:一元運算子++,--只適用於變數,且變數位於運算子的哪一側有不同的效果。當運算子位於變數的左側時,先++(或--)後運算,反之,先運算後++(或--)。
例題6:
1. public class test
6. object o = (object)new foo();
7 . foo foo = (foo)o;
8. = 「 +
9. }
10. }
what is the result?
a. i = 3
b. compilation fails.
c. a classcastexception is thrown at line 6.
d. a classcastexception is thrown at line 7.
解答:a
點評:此題主要考查父類物件和子類物件的引用關係。希望大家明確父類宣告只能訪問到子類中繼承下來的屬於父類的屬性,而不能訪問子類中特有的屬性。
同時我們可以通過「打回原形」的操作,把父類引用強制轉換為子類物件,從而可以訪問到子類中哪些所有的屬性。
例題7:
11. int i =1, j =10;
12. do
16. } while (i <5);
17. = 「 +i+ 「and j = 「+j);
what is the result?
a. i = 6 and j = 5
b. i = 5 and j = 5
c. i = 6 and j = 5
d. i = 5 and j = 6
e. i = 6 and j = 6
解答:d
點評:do-while結果首先執行一下表示式,然後在去判斷條件。這樣的題目最好動手畫一畫,結果就自然明了了。
例題8:
1. class a
3. }
4.5. class b extends a
which two statements are true? (choose two)
a. class b』s constructor is public.
b. class b』s constructor has no arguments.
c. class b』s constructor includes a call to this().
d. class b』s constructor includes a call to super().
解答:b、d
點評:由於父類是無參的構造方法,所以子類可以是無參或帶有任何引數的構造方法,它們都會預設的呼叫super()方法。
例題9:
1. public inte***ce foo
which three are equivalent to line 2? (choose three)
a. final int k = 4;
b. public int k = 4;
c. static int k = 4;
d. abstract int k = 4;
e. volatile int k = 4;
f. protected int k = 4;
解答:a、b、c
點評:介面中的屬性和成員方法修飾符只能是預設的或者public,並且它們都是靜態常量,所以我們一定要對其進行初始化賦值操作。
例題10:
1. package test1;
2. public class test1
1. package test2;
2. public class test2 extends {
3. public static void main(string args) {
unit 1 同步試題 含聽力材料 有答案
my classroom 同步試題 listening 聽力部分 i.listen and choose.聽錄音,選出你所聽到句子中的單詞。1.a.window b.picture c.computer 2.a.door b.floor c.blackboard 3.a.cat b.cake c.m...
機械原理試題 有答案
自測題1 一 選擇題 每小題1分,共10分 1.構件是機械中獨立 a 單元。a.製造 b.運動 c.分析 2.在一般情況下,機構具有確定運動的條件是原動件數目等於 c a.從動件 b.最終執行構件 c.自由度 d.1 3.一般情況下機構的對稱部分可能產生 c a.復合鉸鏈 b.區域性自由度 c.虛約...
果樹試題1答案
果樹栽培 試題1 答案 一 名詞解釋 1 果樹 多年生植物,是能生產可供食用的果實或種子及其砧木的總稱。2 種子休眠 有生命的種子,由於內外條件的影響而不能發芽的現象叫種子休眠。3 新稍 落葉以前的當年生枝稍叫新稍。4 相助作用 當一元素進入果樹體內,另一元素或多元素隨之增加的現象叫相助作用。5 花...