版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、JAVA認(rèn)證歷年真題:SCJP考試真題和解析例題1: Choose the three valid identifiers from those listed below. A. IDoLikeTheLongNameClass B. $byte C. const D. _ok E. 3_case 解答:A, B, D 點(diǎn)評(píng):Java中的標(biāo)示符必須是字母、美元符($)或下劃線(_)開頭。關(guān)鍵字與保留字不能作為標(biāo)示符。選項(xiàng)C中的const是Java的保留字,所以不能作標(biāo)示符。選項(xiàng)E中的3_case以數(shù)字開頭,違反了Java的規(guī)則。 例題2: How can you force garbage co
2、llection of an object? A. Garbage collection cannot be forced B. Call System.gc(). C. Call System.gc(), passing in a reference to the object to be garbage collected. D. Call Runtime.gc(). E. Set all references to the object to new values(null, for example). 解答:A 點(diǎn)評(píng):在Java中垃圾收集是不能被強(qiáng)迫立即執(zhí)行的。調(diào)用System.gc(
3、)或Runtime.gc()靜態(tài)方法不能保證垃圾收集器的立即執(zhí)行,因?yàn)?,也許存在著更高優(yōu)先級(jí)的線程。所以選項(xiàng)B、D不正確。選項(xiàng)C的錯(cuò)誤在于,System.gc()方法是不接受參數(shù)的。選項(xiàng)E中的方法可以使對(duì)象在下次垃圾收集器運(yùn)行時(shí)被收集。例題3:Consider the following class: 1. class Test(int i) 2. void test(int i) 3. System.out.println(“I am an int.”); 4. 5. void test(String s) 6. System.out.println(“I am a string.”); 7
4、. 8. 9. public static void main(String args) 10. Test t=new Test(); 11. char ch=“y”; 12. t.test(ch); 13. 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() t
5、hat 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 點(diǎn)評(píng):在第12行,16位長(zhǎng)的char型變量ch在編譯時(shí)會(huì)自動(dòng)轉(zhuǎn)化為一個(gè)32位長(zhǎng)的int型,并在運(yùn)行時(shí)傳給void
6、test(int i)方法。Question No: 1 Given: 1. public class test ( 2. public static void main (String args) 3. int i = 0xFFFFFFF1; 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 compilati
7、on to fail. Answer: DQuestion No: 2 Given: Integer i = new Integer (42); Long 1 = new Long (42); Double d = new Double (42.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
8、: 1. public class test ( 2. private static int j = 0; 3. 4. private static boolean methodB(int k) ( 5. j += k; 6. return true; 6. ) 7. 8. public static void methodA(int i) 9. boolean b: 10. b = i 10 | methodB (4); 11. b = i 10 | methodB (8); 12. ) 13. 14. public static void main (String args ( 15. m
9、ethodA (0); 16. system.out.printIn(j); 17. ) 18. ) What is the result? A. The program prints “0” B. The program prints “4” C. The program prints “8” D. The program prints “12” E. The code does not complete. Answer: B Question No: 4 Given 1. Public class test ( 2. Public static void main (String args
10、) ( 3. System.out.printIn (6 3); 4. ) 5. ) What is the output? Answer: 5 Question No: 5 Given: 1. public class Foo 2. public static void main (String args) 3. StringBuffer a = new StringBuffer (“A”); 4. StringBuffer b = new StringBuffer (“B”); 5. operate (a,b); 6. system.out.printIna + “,” +b; 7. )
11、8. static void operate (StringBuffer x, StringBuffer y) 9. x.append y; 10. y = x; 11. ) 12. What is the result? A. The code compiles and prints “A,B”. B. The code compiles and prints “A,A”. C. The code compiles and prints “B,B”. D. The code compiles and prints “AB,B”. E. The code compiles and prints
12、 “AB,AB”. F. The code does not compile because “+” cannot be overloaded for StringBuffer. Answer: D | Question No: 6 Exhibit: 1. Public class test ( 2. Public static void stringReplace (String text) ( 3. Text = text.replace (j , i); 4. ) 5. 6. public static void bufferReplace (StringBuffer text) ( 7
13、. text = text.append (“C”) 8. ) 9. 10. public static void main (String args ( 11. String textString = new String (“java”); 12. StringBuffer text BufferString = new StringBuffer (“java”); 13. 14. stringReplace (textString); 15. BufferReplace (textBuffer); 16. 17. System.out.printIn (textString + text
14、Buffer); 18. 19. ) What is the output? Answer: javajavaCQuestion No: 7 Exhibit: 1. public class test 2. public static void add3 (Integer i) 3. int val = Value ( ); 4. val += 3; 5. i = new Integer (val); 6. 7. 8. public static void main (String args ) 9. Integer i = new Integer (0); 10. add3 (i)
15、; 11. system.out.printIn (Value ( ) ); 12. 13. ) What is the result? A. Compilation will fail. B. The program prints “0”. C. The program prints “3”. D. Compilation will succeed but an exception will be thrown at line 3. Answer: B Question No: 8 Given: 1. public class ConstOver 2. public ConstOv
16、er (int x, int y, int z) 3. 4. Which two overload the ConstOver constructor? (Choose Two) A. ConstOver ( ) B. Protected int ConstOver ( ) C. Private ConstOver (int z, int y, byte x) D. Public Object ConstOver (int x, int y, int z) E. Public void ConstOver (byte x, byte y, byte z) Answer: A, C Questi
17、on No: 9 Given: 1. public class MethodOver 2. public void setVar (int a, int b, float c) 3. 4. Which two overload the setVar method? (Choose Two) 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
18、. Public int setVar (int a, int b, float c) (return a;) E. Protected float setVar (int a, int b, float c) (return c;) Answer: A, C Question No: 10 Given: 1. class BaseClass 2. Private float x = 1.0f ; 3. protected float getVar ( ) ( return x;) 4. 5. class Subclass extends BaseClass ( 6. private floa
19、t x = 2.0f; 7. /insert code here 8. ) Which two are valid examples of method overriding? (Choose Two) A. Float getVar ( ) return x; B. Public float getVar ( ) return x; C. Float double getVar ( ) return x; D. Public float getVar ( ) return x; E. Public float getVar (float f ) return f; Answer: B, D
20、Question No: 11 Which two demonstrate an “is a” relationship? (Choose Two) A. public interface Person public class Employee extends Person B. public interface Shape public class Employee extends Shape C. public interface Color public class Employee extends Color D. public class Species public class
21、Animal (private Species species;) E. interface Component Class Container implements Component ( Private Component children; ) Answer: D, E Question No: 12 Which statement is true? A. An anonymous inner class may be declared as final. B. An anonymous inner class can be declared as private. C. An anon
22、ymous inner class can implement multiple interfaces. D. An anonymous inner class can access final variables in any enclosing scope. E. Construction of an instance of a static inner class requires an instance of the enclosing outer class. Answer: D | Question No 13 Given: 1. package foo; 2. 3. public
23、 class Outer ( 4. public static class Inner ( 5. ) 6. ) Which statement is true? A. An instance of the Inner class can be constructed with “new Outer.Inner ()” B. An instance of the inner class cannot be constructed outside of package foo. C. An instance of the inner class can only be constructed fr
24、om within the outer class. D. From within the package bar, an instance of the inner class can be constructed with “new inner()” Answer: A Question No 14 Exhibit: 1. public class enclosingone ( 2. public class insideone 3. ) 4. public class inertest( 5. public static void main (stringargs)( 6. enclos
25、ingone eo= new enclosingone (); 7. /insert code here 8. ) 9. ) Which statement at line 7 constructs an instance of the inner class? A. InsideOnew ei= eo.new InsideOn(); B. Eo.InsideOne ei = eo.new InsideOne(); C. InsideOne ei = EnclosingOne.new InsideOne(); D. EnclosingOne.InsideOne ei = eo.new Insi
26、deOne(); Answer: D Question No 15 Exhibit: 1. interface foo 2. int k = 0; 3. 4. 5. public class test implements Foo ( 6. public static void main(String args) ( 7. int i; 8. Test test = new test (); 9. i= test.k; 10.i= Test.k; 11.i= Foo.k; 12.) 13.) 14. What is the result? A. Compilation succeeds. B.
27、 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 Question No 16 Given: 1. /point X 2. public class foo ( 3. public static void main (String
28、args) throws Exception 4. printWriter out = new PrintWriter (new 5. java.io.outputStreamWriter (System.out), true; 6. out.printIn(“Hello”); 7. 8. ) Which statement at PointX on line 1 allows this code to compile and run? A. Import java.io.PrintWriter; B. Include java.io.PrintWriter; C. Import java.i
29、o.OutputStreamWriter; D. Include java.io.OutputStreamWriter; E. No statement is needed. Answer: A Question No 17 Which two statements are reserved words in Java? (Choose Two) A. Run B. Import C. Default D. Implement Answer: B, C Question No 18 Which three are valid declarations of a float? (Choose T
30、hree) A. Float foo = -1; B. Float foo = 1.0; C. Float foo = 42e1; D. Float foo = 2.02f; E. Float foo = 3.03d; F. Float foo = 0x0123; Answer: A, D, F310-025 Leading the way in IT testing and certification tools, Question No 19 Given: 8. int index = 1; 9. boolean test = new Boolean; 1
31、0. boolean foo= test index; What is the result? A. Foo has the value of 0. B. Foo has the value of null. C. Foo has the value of true. D. Foo has the value of false. E. An exception is thrown. F. The code will not compile. Answer: D Question No 20 Given: 1. public class test( 2. public static void m
32、ain(stringargs) 3. string foo = args 1; 4. string foo = args ; 5. string foo = args ; 6. 7. And command line invocation: Java Test red green blue What is the result? A. Baz has the value of “” B. Baz has the value of null C. Baz has the value of “red” D. Baz has the value of “blue” E. Bax has the va
33、lue of “green” F. The code does not compile. G. The program throws an exception. Answer: G Question No 21 Given: 8. int index = 1; 9. int foo = new int ; 10.int bar = foo index; 11.int baz = bar + index; What is the result? A. Baz has the value of 0 B. Baz has the value of 1 C. Baz has the value of
34、2 D. An exception is thrown. E. The code will not compile. Answer: B Question No 22 Given: 1. public class foo 2. public static void main (Stringargs) 3. String s; 4. system.out.printIn (“s=” + s); 5. 6. What is the result? A. The code compiles and “s=” is printed. B. The code compiles and “s=null”
35、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 when toString is called. Answer: C Question No 23 Which will declare a method that forces a sub
36、class to implement it? A. Public double methoda(); B. Static void methoda (double d1) C. Public native double methoda(); D. Abstract public void methoda(); E. Protected void methoda (double d1) Answer: D Question No 24 You want subclasses in any package to have access to members of a superclass. Whi
37、ch is the most restrictive access modifier that will accomplish this objective? A. Public B. Private C. Protected D. Transient E. No access modifier is qualified Answer: C Question No 25 Given: 1. abstract class abstrctIt 2. abstract float getFloat (); 3. ) 4. public class AbstractTest extends Abstr
38、actIt 5. private float f1= 1.0f; 6. private float getFloat () return f1; 7. What is the result? A. Compilation is successful. B. An error on line 6 causes a runtime failure. C. An error at line 6 causes compilation to fail. D. An error at line 2 causes compilation to fail. Answer: C Question No 26 E
39、xhibit: 1. public class test( 2. public int aMethod() 3. static int i=0; 4. i+; 5. return I; 6. ) 7. public static void main (String args) 8. test test = new test(); 9. test.aMethod(); 10.int j = test.aMethod(); 11.System.out.printIn(j); 12. 13. What is the result? A. Compilation will fail. B. Compi
40、lation will succeed and the program will print “0” C. Compilation will succeed and the program will print “1” D. Compilation will succeed and the program will print “2” Answer: D | Question No 27 Given: 1. class super 2. public float getNum() return 3.0f; 3. ) 4. 5. public class Sub extends Super 6.
41、 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) retrun 4.0f; Answer: B Question No 28 Which declaration prevents creating a subclass of an outer class?
42、 A. Static class FooBar B. Private class FooBar C. Abstract public class FooBar D. Final public class FooBar E. Final abstract class FooBar Answer: D Question No 29 Given: 1. byte arry1, array2; 2. byte array3 ; 3. byte array4; If each array has been initialized, which statement will cause a compile
43、r error? A. Array2 = array1; B. Array2 = array3; C. Array2 = array4; D. Both A and B E. Both A and C F. Both B and C Answer: F Question No 30 Exhibit: 1. class super ( 2. public int I = 0; 3. 4. public super (string text) ( 5. I = 1 6. ) 7. ) 8. 9. public class sub extends super ( 10. public sub (st
44、ring text) ( 11. i= 2 12. ) 13. 14. public static void main (straing args) ( 15. sub sub = new sub (“Hello”); 16. system.out. PrintIn(sub.i); 17. ) 18. ) What is the result? A. Compilation will fail. B. Compilation will succeed and the program will print “0” C. Compilation will succeed and the progr
45、am will print “1” D. Compilation will succeed and the program will print “2” Answer: A Question No 31 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. Int B. Byte C. Long D. Short E
46、. Float F. Double Answer: F Question No 32 Given the ActionEvent, which method allows you to identify the affected component? A. GetClass. B. GetTarget. C. GetSource. D. GetComponent. E. GetTargetComponent. Answer: C Question No 33 Which is a method of the MouseMotionListener interface? A. Public vo
47、id mouseMoved(MouseEvent) B. Public boolean mouseMoved(MouseEvent) C. Public void mouseMoved(MouseMotionEvent) D. Public boolean MouseMoved(MouseMotionEvent) E. Public boolean mouseMoved(MouseMotionEvent) Answer: A Question No 34 Exhibit: 1. import java.awt*; 2. 3. public class X extends Frame ( 4.
48、public static void main(string args) ( 5. X x = new X (); 6. X.pack(); 7. x.setVisible(true); 8. ) 9. 10. public X () ( 11. setlayout (new GridLayout (2,2); 12. 13. Panel p1 = new panel(); 14. Add(p1); 15. Button b1= new Button (“One”); 16. P1.add(b1); 17. 18. Panel p2 = new panel(); 19. Add(p2); 20
49、. Button b2= new Button (“Two”); 21. P2.add(b2); 22. 23. Button b3= new Button (“Three”); 24. add(b3); 25. 26. Button b4= new Button (“Four”); 27. add(b4); 28. ) 29. ) Which two statements are true? (Choose Two) A. All the buttons change height if the frame height is resized. B. All the buttons chan
50、ge width if the Frame width is resized. C. The size of the button labeled “One” is constant even if the Frame is resized. D. Both width and height of the button labeled “Three” might change if the Frame is resized. Answer: C, D | Question No 35 You are assigned the task of building a panel containin
51、g a TextArea at the top, a label directly below it, and a button directly below the label. If the three components are added directly to the panel. Which layout manager can the panel use to ensure that the TextArea absorbs all of the free vertical space when the panel is resized? A. GridLayout. B. C
52、ardLayout. C. FlowLayout. D. BorderLayout. E. GridBagLayout. Answer: E Question No 36 Which gets the name of the parent directory file “file.txt”? A. String name= File.getParentName(“file.txt”); B. String name= (new File(“file.txt”).getParent(); C. String name = (new File(“file.txt”).getParentName()
53、; D. String name= (new File(“file.txt”).getParentFile(); E. Directory dir=(new File (“file.txt”).getParentDir(); String name= dir.getName(); Answer: B Question No 37 Which can be used to encode charS for output? A. Java.io.OutputStream. B. Java.io.OutputStreamWriter. C. Java.io.EncodeOutputStream. D
54、. Java.io.EncodeWriter. E. Java.io.BufferedOutputStream. Answer: B Question No 38 The file “file.txt” exists on the file system and contsins ASCII text. Given: 38. try 39. File f = new File(“file.txt”); 40. OutputStream out = new FileOutputStream(f, true); 41. 42. catch (IOException) What is the result? A. The code does not compile. B. The code runs and no change is made to the file. C. The code runs and sets the length of the file to 0. D. An exception is thrown because the file is not closed. E. The code runs and deletes the file from th
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2026年黃埔海關(guān)國(guó)際旅行衛(wèi)生保健中心公開招聘非占編聘用人員的備考題庫帶答案詳解
- 2026年衡陽市第一人民醫(yī)院婦產(chǎn)科醫(yī)師招聘?jìng)淇碱}庫及1套參考答案詳解
- 2026年智鏈電磁材料(山東)有限公司招聘?jìng)淇碱}庫有答案詳解
- 2026年瀘州市部分企事業(yè)單位人才引進(jìn)88人備考題庫及參考答案詳解
- 2026年溫州市人民醫(yī)院(溫州市婦幼保健院)勞務(wù)派遣人員招聘?jìng)淇碱}庫(五)及一套參考答案詳解
- 養(yǎng)老院入住老人糾紛調(diào)解與處理制度
- 2026年首都醫(yī)學(xué)科學(xué)創(chuàng)新中心孫少聰實(shí)驗(yàn)室招聘生物備考題庫學(xué)分析科研助理及完整答案詳解一套
- 2026年黃石市消防救援支隊(duì)招聘政府專職消防員18人備考題庫及參考答案詳解
- 企業(yè)內(nèi)部保密協(xié)議簽訂制度
- 2025年檢疫機(jī)構(gòu)傳染病防控操作手冊(cè)
- 2026凱翼汽車全球校園招聘(公共基礎(chǔ)知識(shí))綜合能力測(cè)試題附答案
- 山東省威海市環(huán)翠區(qū)2024-2025學(xué)年一年級(jí)上學(xué)期1月期末數(shù)學(xué)試題
- 外貿(mào)公司采購專員績(jī)效考核表
- 胸腺瘤伴重癥肌無力課件
- 十五五安全生產(chǎn)規(guī)劃思路
- 剪刀車專項(xiàng)施工方案
- 授信合同與借款合同(標(biāo)準(zhǔn)版)
- 2024-2025學(xué)年四川省綿陽市七年級(jí)(上)期末數(shù)學(xué)試卷
- 道路清掃保潔、垃圾收運(yùn)及綠化服務(wù)方案投標(biāo)文件(技術(shù)標(biāo))
- 合成藥物催化技術(shù)
- 【語文】福建省福州市烏山小學(xué)小學(xué)三年級(jí)上冊(cè)期末試題(含答案)
評(píng)論
0/150
提交評(píng)論