九九热最新网址,777奇米四色米奇影院在线播放,国产精品18久久久久久久久久,中文有码视频,亚洲一区在线免费观看,国产91精品在线,婷婷丁香六月天

ocjp考試題庫-

上傳人:海盜 文檔編號(hào):20612208 上傳時(shí)間:2021-04-04 格式:DOC 頁數(shù):66 大?。?55.01KB
收藏 版權(quán)申訴 舉報(bào) 下載
ocjp考試題庫-_第1頁
第1頁 / 共66頁
ocjp考試題庫-_第2頁
第2頁 / 共66頁
ocjp考試題庫-_第3頁
第3頁 / 共66頁

本資源只提供3頁預(yù)覽,全部文檔請(qǐng)下載后查看!喜歡就下載吧,查找使用更方便

10 積分

下載資源

資源描述:

《ocjp考試題庫-》由會(huì)員分享,可在線閱讀,更多相關(guān)《ocjp考試題庫-(66頁珍藏版)》請(qǐng)?jiān)谘b配圖網(wǎng)上搜索。

1、1. Given:1. public class returnIt 2. returnType methodA(byte x, double y)3. return (short) x/y * 2;4. 5. What is the valid returnType for methodA in line 2?A. intB. byteC. longD. shortE. floatF. double Answer F注釋:short類型的x,除以double類型的y,再乘int的2,所以結(jié)果是double類型的。注意第三行的強(qiáng)制轉(zhuǎn)換,只是轉(zhuǎn)換了x。2. 1) class Super 2) pu

2、blic float getNum()return 3.0f; 3) 4) 5) public class Sub extends Super 6) 7) which method, placed at line 6, will cause a compiler error? A. public float getNum()return 4.0f; B. public void getNum() C. public void getNum(double d) D. public double getNum(float d)return 4.0d; Answer :B注意這道題主要考的是方法的o

3、verload和override。對(duì)于overload,只有參數(shù)列表不同,才做為標(biāo)準(zhǔn),而返回值和訪問控制關(guān)鍵字不能做為標(biāo)準(zhǔn),所以B錯(cuò)在方法名相同,但只有返回值不同,這是錯(cuò)的。C和D是正確的overload。對(duì)于override,則訪問控制關(guān)鍵字只能更加公有化,異常只能是超類方法拋出的異常的子類,也可以不拋出。返回類型,參數(shù)列表必須精確匹配。所以A是正確的override。 3. 1)public class Foo 2) public static void main(String args) 3) tryreturn; 4) finally System.out.println(Finall

4、y); 5) 6) what is the result? A. The program runs and prints nothing.B. The program runs and prints “Finally”.C. The code compiles, but an exception is thrown at runtime.D. The code will not compile because the catch block is missing. Answer:btry.catch.finally的問題。程序中如果遇到return,則finally塊先被執(zhí)行,然后再執(zhí)行ret

5、run,而finally塊后面的語句將不被執(zhí)行。如果遇到System.exit(1),則finally塊及其后的語句都不執(zhí)行,整個(gè)程序退出,還執(zhí)行什么呀。 4. 1) public class Test 2) public static String output=; 3) public static void foo(int i) 4) try 5) if(i=1) 6) throw new Exception(); 7) 8) output +=1; 9) 10) catch(Exception e) 11) output+=2; 12) return; 13) 14) finally 1

6、5) output+=3; 16) 17) output+=4; 18) 19) public static void main(String args) 20) foo(0); 21) foo(1); 22) 23) 24) what is the value of output at line 22? Asnwer:13423執(zhí)行第一個(gè)foo(0)時(shí),執(zhí)行第8條語句,output=1,然后執(zhí)行語句15,output=13,然后是17條,output=134,因?yàn)槭莝tatic類型的變量,所以任何對(duì)其值的修改都有效。執(zhí)行第二條foo(1),先執(zhí)行語句5,結(jié)果拋出異常,轉(zhuǎn)到catch塊,out

7、put=1342,finally任何情況下都執(zhí)行,所以output=13423,然后return跳出方法體,所以output=134235 1)public class IfElse 2)public static void main(String args) 3)if(odd(5) 4)System.out.println(odd); 5)else 6)System.out.println(even); 7) 8)public static int odd(int x)return x%2; 9) what is output? Answer: 編譯錯(cuò)誤。if中的判斷條件的結(jié)果必須是bool

8、ean類型的。注意這里說的是結(jié)果. 6 1)class ExceptionTest 2)public static void main(String args) 3)try 4)methodA(); 5)catch(IOException e) 6)System.out.println(caught IOException); 7)catch(Exception e) 8)System.out.println(caught Exception); 9) 10) 11) If methodA() throws a IOException, what is the result? Answer:

9、caught IOException如果methodA()拋出IOExecption,被語句6捕獲,輸出caught IOException,然后呢?然后就結(jié)束了唄。71)int i=1,j=10; 2)do 3) if(i+-j) continue; 4)while(i5); After Execution, what are the value for i and j? A. i=6 j=5 B. i=5 j=5 C. i=6 j=4 D. i=5 j=6 E. i=6 j=6 Answer: d程序一直循環(huán),直到i=4,j=6時(shí),執(zhí)行完語句3后,i會(huì)+,這時(shí)i就等于了5,continue

10、后就不能再循環(huán)了,所以選D。81)public class X 2) public Object m() 3) Object o=new Float(3.14F); 4) Object oa=new Object1; 5) oa0=o; 6) o=null; 7) oa0=null; 8) System.out.println(oa0); 9) 10) which line is the earliest point the object a refered is definitely elibile to be garbage collectioned? A.After line 4 B.

11、After line 5 C.After line 6 D.After line 7 E.After line 9(that is,as the method returns) Answer: d當(dāng)執(zhí)行第6行后,仍然有對(duì)象指向o,所以o不能滿足條件,當(dāng)?shù)?條語句被執(zhí)行后,就再也沒有對(duì)象指向o了,所以選D。9 1) interface Foo 2) int k=0; 3) 4) public class Test implements Foo 5) public static void main(String args) 6) int i; 7) Test test =new Test(); 8

12、) i=test.k; 9) i=Test.k; 10) i=Foo.k; 11) 12) What is the result?A. Compilation succeeds.B. An error at line 2 causes compilation to fail.C. An error at line 9 causes compilation to fail.D. An error at line 10 causes compilation to fail.E. An error at line 11 causes compilation to fail. Answer: A編譯通

13、過,通過測(cè)試的10 what is reserved(保留) words in java? A. run B. default C. implement D. import Answer: b,D111)public class Test 2) public static void main(String args) 3) String foo=args1; 4) Sring bar=args2; 5) String baz=args3; 6) 7) java Test Red Green Blue what is the value of baz? A. baz has value of B

14、. baz has value of null C. baz has value of Red D. baz has value of Blue E. baz has value of Green F. the code does not compile G. the program throw an exception Answer: G當(dāng)執(zhí)行java Test Red Green Blue時(shí),數(shù)組args只有012,運(yùn)行時(shí)ArrayIndexOutOfBoundsException這個(gè)異常會(huì)被拋出,數(shù)組越界。12int index=1; int foo=new int3; int bar=

15、fooindex; int baz=bar+index; what is the result? A. baz has a value of 0 B. baz has value of 1 C. baz has value of 2 D. an exception is thrown E. the code will not compile Answer: b數(shù)組初始化后默認(rèn)值是0,所以baz=0+1=113 which three are valid declaraction(行為) of a float? A. float foo= -1; B. float foo=1.0; C. flo

16、at foo=42e1; D. float foo=2.02f; E. float foo=3.03d; F. float foo=0x0123; Answer: A,D,F(xiàn)其它的系統(tǒng)都會(huì)認(rèn)為是double類型,所以出錯(cuò)。說一下A和C的區(qū)別吧,-1系統(tǒng)會(huì)認(rèn)為是一個(gè)int類型,把int類型再賦給float類型的foo,當(dāng)然沒錯(cuò)了,可C就不同啦,42e1是int類型嗎?141)public class Foo 2) public static void main(String args) 3) String s; 4) System.out.println(s=+s); 5) 6) what is

17、 the result? A. The code compiles and “s=” is printed.B. The code compiles and “s=null” is printed.C. The code does not compile because string s is not initialized(初始化). D. The code does not compile because string s cannot be referenced(引用).E. The code compiles, but a NullPointerException is thrown

18、when toString is called. Answer:C只有實(shí)例變量系統(tǒng)才給予自動(dòng)賦默認(rèn)值的這種待遇 15 1) public class Test 2) public static void main(String args) 3) int i=oxFFFFFFF1; 4) int j=i; 5) 6) 7) which is decimal value of j at line 5? A. 0 B.1 C.14 D.-15 E. compile error at line 3 F. compile error at line 4 Answer: C算一算就知道了。 16 floa

19、t f=4.2F; Float g=new Float(4.2F); Double d=new Double(4.2); Which are true? A. f=g B. g=g C. d=f D. d.equals(f) E d.equals(g) F. g.equals(4.2); Answer: B=兩邊類型不同不相等。所以A和C不等。equals只能用于引用類型,不能用于基本類型,所以D不對(duì),而且兩邊類型不兼容的話,即使對(duì)象的內(nèi)容一樣,也不相等,所以E和F不對(duì)。17 1)public class Test 2) public static void add3(Integer i) 3

20、) int val=i.intValue(); 4) val+=3; 5) i=new Integer(val); 6) 7) public static void main(String args) 8) Integer i=new Integer(0); 9) add3(i); 10) System.out.println(i.intValue(); 11) 12) what is the result? A. compile fail B.print out 0 C.print out 3 D.compile succeded but exception at line 3 Answer

21、: b在第五行里,程序又操作了New,重新分配了內(nèi)存空間。所以此i非彼i啦。181)public class Test 2) public static void main(String args) 3) System.out.println(63); /為XOR4) 5) what is output? Answer: 5算唄。191) public class Test 2) public static void stringReplace(String text) 3) text=text.replace(j,l); 4) 5) public static void bufferRepl

22、ace(StringBuffer text) 6) text=text.append(c); 7) 8) public static void main(String args) 9) String textString=new String(java); 10) StringBuffer textBuffer=new StringBuffer(java); 11) StringReplace(textString); 12) bufferReplace(textBuffer); 13) System.out.println(textString+textBuffer); 14) 15) wh

23、at is the output? Answer: javajavactextString是String類型的,具有不變性,語句3其實(shí)是創(chuàng)建了一個(gè)新的字符串,而不是修改原來的textString,而對(duì)于StringBuffer類型的對(duì)象,則所有修改都是實(shí)在的。所以在語句6中textBuffer變成了javac,所以輸出為javajavac。 201)public class ConstOver 2) public ConstOver(int x, int y, int z) 3) which two overload the ConstOver constructor? A.ConstOver

24、() B.protected int ConstOver() C.private ConstOver(int z, int y, byte x) D.public void ConstOver(byte x, byte y, byte z) E.public Object ConstOver(int x, int y, int z) Answer: a,c主要的問題是overload,參數(shù)列表必須不同,方法名相同,訪問控制無限制。也無異常限制。這道題因?yàn)槭菢?gòu)造器,所以B,D和E不對(duì),因?yàn)闃?gòu)造器不能有返回類型。211)public class MethodOver 2) public void

25、setVar(int a, int b, float c) 3) which overload the setVar? A.private void setVar(int a, float c, int b) B.protected void setVar(int a, int b, float c) C.public int setVar(int a, float c, int b)return a; D.public int setVar(int a, float c)return a; Answer: a,c,doverload無訪問控制限制,所以A對(duì),順序也屬于參數(shù)列表,順序不同也一樣

26、是overload,所以C正確,D當(dāng)然正確了,參數(shù)列表明顯不同。22 1)class EnclosingOne 2)public class InsideOne 3) 4)public class InnerTest 5) public static void main(String args) 6) EnclosingOne eo=new EnclosingOne(); 7) /insert code here 8) 9) A.InsideOne ei=eo.new InsideOne(); B.eo.InsideOne ei=eo.new InsideOne(); C.InsideOne

27、ei=EnclosingOne.new InsideOne(); D.InsideOne ei=eo.new InsideOne(); E.EnclosingOne.InsideOne ei=eo.new InsideOne(); Answer: e這里邊的一些形式是固定的。(1)靜態(tài)方法訪問非靜態(tài)內(nèi)類: 方法為: Outer myouter=new Outer();這里的myouter是創(chuàng)建的外部類的對(duì)象。 Outer.Inner myinner=myouter.new Inner();myinner是內(nèi)類的對(duì)象。 然后再myinner.showName();showName()是外類中的非

28、靜態(tài)方法。(2)非靜態(tài)方法訪問非靜態(tài)內(nèi)類 直接創(chuàng)建該內(nèi)部類的對(duì)象:new Inner().showName();(3)靜態(tài)方法訪問靜態(tài)內(nèi)類: 也是直接創(chuàng)建該內(nèi)部類的對(duì)象,即Inner myinner = new Inner(),或者Outer.Inner myinner = new Outer.Inner()也行得通哦。23 What is is a relation? A.public interface Color public class Shapeprivate Color color; B.interface Component class Container implements

29、Component private Component children; C.public class Species public class Animalprivate Species species; Answer: bis a 意思為是什么:定義了一個(gè)超類和一個(gè)子類之間的一種直接關(guān)系:子類是超類的一種。也即是繼承的關(guān)系24 1)package foo; 2) 3)public class Outer 4)public static class Inner 5) 6) which is true to instantiated(事例) Inner class inside Outer?

30、 A. new Outer.Inner() B. new Inner() Answer: a,b25class BaseClass private float x=1.0f; private float getVar()return x; class SubClass extends BaseClass private float x=2.0f; /insert code what are true to override getVar()? A.float getVar() B.public float getVar() C.public double getVar() D.protecte

31、d float getVar() E.public float getVar(float f) Answer: a,b,d又是override的問題,參數(shù)列表和返回值以及方法名(好像是費(fèi)話)必須精確匹配,訪問控制要更公有化,如果拋出異常,那么必須異常本身或其子集或什么都不拋. 26 public class SychTest private int x; private int y; public void setX(int i) x=i; public void setY(int i)y=i; public Synchronized void setXY(int i) setX(i); se

32、tY(i); public Synchronized boolean check() return x!=y; Under which conditions will check() return true when called from a different class? A.check() can never return true. B.check() can return true when setXY is callled by multiple threads. C.check() can return true when multiple threads call setX

33、and setY separately. D.check() can only return true if SychTest is changed allow x and y to be set separately. Answer: c 27Given:1. public class SyncTest (2. private int x;3. private int y;4. private synchronized void setX (int i) (x=1;)5. private synchronized void setY (int i) (y=1;)6. public void

34、setXY(int 1)(set X(i); setY(i);)7. public synchronized Boolean check() (return x !=y;)8. ) Under which conditions will check () return true when called from a different class? A. Check() can never return trueB. Check() can return true when setXY is called by multiple threadsC. Check() can return tru

35、e when multiple threads call setX and setY separately. D. Check() can only return true if SyncTest is changed to allow x and y to be set separately. Answer:B 28Given:1. public class SyncTest 2. private int x;3. private int y;4. public synchronized void setX (int i) (x=1;)5. public synchronized void

36、setY (int i) (y=1;)6. public synchronized void setXY(int 1)(set X(i); setY(i);)7. public synchronized Boolean check() (return x !=y;)8. )Under which conditions will check () return true when called from a different class?A. Check() can never return true.B. Check() can return true when setXY is calle

37、d by multiple threads.C. Check() can return true when multiple threads call setX and setY separately.D. Check() can only return true if SyncTest is changed to allow x and y to be set separately. Answer: A哪一個(gè)不加鎖,就從哪一個(gè)入手,但這道題全都加鎖了,所以先A。29 1)public class X implements Runnable 2)private int x; 3)private

38、 int y; 4)public static void main(String args) 5) X that =new X(); 6) (new Thread(that).start(); 7) (new Thread(that).start(); 9) public synchronized void run() 10) for(;) 11) x+; 12) y+; 13) System.out.println(x=+x+,y=+y); 14) 15) 16) what is the result? A.An error at line 11 causes compilation to

39、fail.B.Errors at lines 6 and 7cause compilation to fail.C.The program prints pairs of values for x and y that might not always be the same on the same line (for example, “x=2, y=1”)D.The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In

40、 addition, each value appears twice (for example, “x=1, y=1” followed by “x=1, y=1”)E.The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” followed by “x=2, y=2”) Answer: E這道題

41、有問題,當(dāng)兩個(gè)線程同名時(shí),輸出x=1,y=1,但只一次,而當(dāng)兩個(gè)線程不同名時(shí),輸出就是兩次。理論上加鎖時(shí),線程1會(huì)執(zhí)行直到結(jié)束,然后線程2才會(huì)開始執(zhí)行。30 Click the exhibit button:1. public class X implements Runnable( 2. private int x; 3. private int y; 4. 5. public static void main(Stringargs) 6. X that = new X(); 7. (new Thread(that).start(); 8. (new Thread(that).start()

42、; 9. ) 10. 11. public void run() ( 12. for (;) ( 13. x+; 14. y+; 15. System.out.printIn(“x=” + x + “, y = ” + y); 16. ) 17. ) 18. ) What is the result?A. Errors at lines 7 and 8 cause compilation to fail.B. The program prints pairs of values for x and y that might not always be the same on the same

43、line (for example, “x=2, y=1”).C. The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” followed by “x=1, y=1”).D. The program prints pairs of values for x and y that are alway

44、s the same on the same line (for example, “x=1, y=1”.) In addition, each value appears only for once (for example, “x=1, y=1” followed by “x=2, y=2”). Answer D這道題也有問題,當(dāng)兩個(gè)線程同名的情況下,只輸出一次,但當(dāng)兩個(gè)線程不同名的情況下,可以清楚的看到兩個(gè)線程是交替執(zhí)行的,x=1,y=1后現(xiàn)可以是任何東西,也可能是另一個(gè)線程的x=1,y=1。31class A implements Runnable int i; public void

45、 run() try Thread.sleep(5000); i=10; catch(InterruptException e) public static void main(String args) try A a=new A(); Thread t=new Thread(a); t.start(); 17) int j=a.i; 19) catch(Exception e) what be added at line line 17,ensure j=10 at line 19? A. a.wait(); B. t.wait(); C. t.join(); D.t.yield(); E.

46、t.notify(); F. a.notify(); G.t.interrupt(); Answer: c32 Given an ActionEvent, which method allows you to identify the affected component?A. public class getClass()B. public Object getSource()C. public Component getSource()D. public Component getTarget()E. public Component getComponent()F. public Com

47、ponent getTargetComponent() Answer: c33import java.awt.*; public class X extends Frame public static void main(String args) X x=new X(); x.pack(); x.setVisible(true); public X() setLayout(new GridLayout(2,2); Panel p1=new Panel(); add(p1); Button b1=new Button(One); p1.add(b1); Panel p2=new Panel();

48、 add(p2); Button b2=new Button(Two); p2.add(b2); Button b3=new Button(Three); p2.add(b3); Button b4=new Button(Four); add(b4); when the frame is resized, A.all change height B.all change width C.Button One change height D.Button Two change height E.Button Three change width F.Button Four change heig

49、ht and width Answer: f341)public class X 2) public static void main(String args) 3) String foo=ABCDE; 4) foo.substring(3); 5) foo.concat(XYZ); 6) 7) what is the value of foo at line 6? Answer: ABCDE問題的關(guān)鍵在于String的不變性,雖然又是substring又是concat的,但都只是創(chuàng)建了一個(gè)新的字符串,原本的foo一直都沒有被改變,也不可能被改變。35Which method is an ap

50、propriate way to determine the cosine of 42 degrees?A. double d = Math.cos(42);B. double d = Math.cosine(42);C. double d = Math.cos(Math.toRadians(42);D. double d = Math.cos(Math.toDegrees(42);E. double d = Math.cosine(Math.toRadians(42); Answer: ctoRadians是把一個(gè)角度轉(zhuǎn)換成一個(gè)弧度,cos方法的參數(shù)必須是以弧度表示的。36public cl

51、ass Test public static void main(String args) StringBuffer a=new StringBuffer(A); StringBuffer b=new StringBuffer(B); operate(a,b); System.out.println(a+,+b); public static void operate(StringBuffer x, StringBuffer y) x.append(y); y=x; what is the output? Answer: AB,B有些不理解。我只能認(rèn)為y=x這名語句沒有改變b。37 Given

52、:13. public class Foo 14. public static void main (String args) 15. StringBuffer a = new StringBuffer (“A”);16. StringBuffer b = new StringBuffer (“B”);17. operate (a,b);18. system.out.printIna + “,” +b;19. )20. static void operate (StringBuffer x, StringBuffer y) 21. y.append (x);22. y = x;23. )24.

53、 What is the result?A.The code compiles and prints “A,B”.B.The code compiles and prints “A, BA”. C.The code compiles and prints “AB, B”. D.The code compiles and prints “AB, AB”. E.The code compiles and prints “BA, BA”. F.The code does not compile because “+” cannot be overloaded for stringBuffer. An

54、swer B 38. 1) public class Test 2) public static void main(String args) 3) class Foo 4) public int i=3; 5) 6) Object o=(Object)new Foo(); 7) Foo foo=(Foo)O; 8) System.out.println(foo.i); 9) 10) what is result? A.compile error at line 6 B.compile error at line 7 C.print out 3 Answer: C簡(jiǎn)單的說,要訪問變量的時(shí)候,看等號(hào)左邊,訪問方法的時(shí)候看等號(hào)右邊,但對(duì)于static類型的方法除外。39public class FooBar public static void main(String args) int i=0,j=5; 4) tp: for(;i+) for(;-j)

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

相關(guān)資源

更多
正為您匹配相似的精品文檔

相關(guān)搜索

關(guān)于我們 - 網(wǎng)站聲明 - 網(wǎng)站地圖 - 資源地圖 - 友情鏈接 - 網(wǎng)站客服 - 聯(lián)系我們

copyright@ 2023-2025  zhuangpeitu.com 裝配圖網(wǎng)版權(quán)所有   聯(lián)系電話:18123376007

備案號(hào):ICP2024067431號(hào)-1 川公網(wǎng)安備51140202000466號(hào)


本站為文檔C2C交易模式,即用戶上傳的文檔直接被用戶下載,本站只是中間服務(wù)平臺(tái),本站所有文檔下載所得的收益歸上傳人(含作者)所有。裝配圖網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)上載內(nèi)容本身不做任何修改或編輯。若文檔所含內(nèi)容侵犯了您的版權(quán)或隱私,請(qǐng)立即通知裝配圖網(wǎng),我們立即給予刪除!