1、英文 SCJP 模拟题200道附答案SCJP 模拟题200道附答案Q1 Which of the following statements are valid, given the following variable declarations: boolean a; boolean b; int c; 1) (a | b) 2)(a | a) 3)(a b) | c 4)(a & c) 5)(a & c) Q2 Which of the following can be applied to constructors: 1) final 2) static 3) synchronized 4
2、) native 5) None of these. Q3 Which of the following retain their preferred size (width and height) when added (individually) to the North section of a container with a BorderLayout (assume that no other components or containers are present in the North section). 1) TextArea 2) Button 3) TextField 4
3、) Checkbox 5) None. All of these mentioned components will only retain their preferred height. Q4 Which of the following are legal names for variables. 1) _int 2) %large 3) $fred 4) Integer 5) 2much Q5 Which of the following are correct ways to create a font. 1) Font f = new Font(Serif, Font.BOLD, 2
4、4); 2) Font f = new Font(Font.SERIF, Bold, 24); 3) Font f = new Font(Serif, Bold, 24); 4) Font f = new Font(Font.SERIF, Font.BOLD, 24); Q6 Select the correct statements regarding the following piece of code. File f = new File(c:large.txt); 1) On execution, a file called large.txt will be created on
5、the local harddisk. 2) The code fails to compile on a UNIX machine, because the directory separator is not correct. 3) A file is NOT created on the harddisk when this code is executed. 4) An exception is thrown at runtime if the file large.txt already exists. 5) The code fails to compile, since this
6、 is not a valid constructor for the File class. Q7 Which of the following statements are correct regarding the RandomAccessFile class? 1) An IOException is thrown if the specified file doesnt exist when created using the r mode. 2) This class has a method which allows a file to be deleted from the h
7、arddisk. 3) It is possible to use this class in conjunction with the DataInputStream class. 4) When used with the rw mode, the specified file is created on a diskdrive, if it doesnt already exist. 5) There are methods to read and write primatives (eg, readInt(), writeInt(), etc). Q8 Consider the fol
8、lowing piece of code and select the correct statement from the following. 1.String s = new String(abcdefgh); 2.s.replace(d, q); 3.System.out.println(s); 1) The code fails to compile, reporting an error at line 2. Strings are immutable, and therefore a replace() method is meaningless. 2) The code com
9、piles correctly, and displays the text abcqefgh. 3) The code compiles correctly, and displays the text abcdefgh. 4) The code compiles, but an exception is thrown when line 2 is executed. 5) The code compiles, but an exception is thrown at line 3. Q9 Which of the following keywords can be applied to
10、the variables or methods of an interface. 1) static 2) private 3) synchronised 4) protected 5) public Q10 True or False. Only Frames can contain menu bars or pull-down menus. 1) True 2) False. Q11 Consider the following piece of code and select the correct statement(s): 1. class A 2. protected int m
11、ethod() 3. 4. 5. 6. class B extends A 7. int method() 8. 9. 1) The code fails to compile, because you cant override a method to be more private than its parent. 2) The code fails to compile, because method() is declared as protected, and is therefore not available to any subclass. 3) The code compil
12、es correctly, but throws a NullPointerException at runtime. 4) The code fails to compile. However, it can be made to compile correctly by prefixing line 7 with the access qualifier public. 5) The code fails to compile. However, it can be made to compile correctly by prefixing line 7 with the access
13、qualifier protected. Q12 True or False. The Throwable class is the superclass of all exceptions in the Java language. 1) True 2) False Q13 Consider the following piece of code (assume the Graphics context g is defined correctly): g.setBackground(Color.red); g.setForeground(Color.white); g.drawLine(1
14、0, 10, 50, 10); g.setForeground(Color.blue); g.drawRect(100, 100, 50, 50); What is displayed when this code is executed. 1) A blue line from (10,10) to (50,10) and a blue rectangle with upper left corner at (100,100). 2) A white line from (10,10) to (50,10) and a blue square with top left corner at
15、(100,100). 3) A white line from (10,10) to (10,50) and a blue square with lower left corner at (100,100). 4) A red line from (10, 10) to (50,10) and a red square with upper left corner at (100,100). 5) Nothing is displayed. You must first issue a repaint() command. Q14 Consider the following piece o
16、f code. class Test public static void main(String args) System.out.println(args3); When the following is typed at the command line, what is displayed: java Test Metallica Justice For All 1) All 2) For 3) Justice 4) Nothing. 5) Nothing. An ArrayIndexOutOfBoundsException is thrown Q15 Consider the fol
17、lowing piece of code. 1. String s = abcd; 2. Integer x = new Integer(3); 3. String s2 = s + 4; 4. s2 = null; 5. s = null; Following the execution of which line above, is the object referenced by s2 available for garbage collection. 1) Line 5 2) It is not possible to say when an object is available f
18、or garbage collection. 3) Line 4 4) The objects are not available until the executing thread is ended. Q16 What is displayed when the following piece of code is compiled and executed: class Test public static void main(String args) Base b = new Subclass(); System.out.println(b.x); System.out.println
19、(b.method(); class Base int x = 2; int method() return x; class Subclass extends Base int x = 3; int method() return x; 1) Nothing. The code fails to compile because the object b is not created in a valid way. 2) 2 3 3) 2 2 4) 3 3 5) 3 2 Q17 What is displayed when the following is executed: String s
20、1 = aaa; s1.concat(bbb); System.out.println(s1); 1) The string aaa. 2) The string aaabbb. 3) Nothing. concat() is not a valid method in the String class. 4) The string bbbaaa. 5) The string bbb. Q18 True or False. The following is a valid way to construct a StringBuffer. StringBuffer sb1 = abcd; 1)
21、True 2) False Q19 What is the output of the following piece of code: 1. int x = 6; 2. double d = 7.7; 3. 4. System.out.println(x d) ? 99.9 : 9); 1) 9 2) 9.0 3) 99.9 4) Nothing. An ArithmeticException is thrown at line 4. 5) 6 Q20 Which of the following can be put in applet tags? (select all the corr
22、ect answers) 1) CODE 2) WIDTH 3) HEIGHT 4) PARAM 5) ARCHIVE Q21 What is printed out following the execution of the code below: 1. class Test 2. static String s; 3. public static void main(String args) 4. int x = 4; 5. if (x 4) 6. System.out.println(Val = + x); 7. else 8. System.out.println(s); 9. 10
23、. Nothing. The code fails to compile because the String s isnt declared correctly. 1) The text Val = null is displayed. 2) The string Val = is displayed. 3) The text null is displayed. 4) A blank line of text is printed. Q22 True or False. The StringBuffer class does not have a concat() method. 1) T
24、rue 2) False Q23 What is displayed when the following piece of code is executed (assume the graphics context, g, is correctly set up): g.drawString(abc, 10, 10); 1) The text abc with the lower left part of a located at x = 10, y = 10. 2) The text abc with the upper left part of a located at x = 10,
25、y = 10. 3) Nothing. This is not a valid method. Q24 True or False. Anonymous classes cannot have constructors. 1) True 2) False Q25 To reference a JAR from a web page, which of the following keywords are used: 1) jar 2) class 3) zip 4) archive 5) package Q26 Analyse the following 2 classes and selec
26、t the correct statements. class A private int x = 0; static int y = 1; protected int q = 2; class B extends A void method() System.out.println(x); System.out.println(y); System.out.println(q); 1) The code fails to compile because the variable x is not available to class B. 2) The code compiles corre
27、ctly, and the following is displayed: 0 1 2 3) The code fails to compile because you cant subclass a class with private variables. 4) Removing the line System.out.println(x) will allow the code to compile correctly. 5) The compiler will complain that the variable x in class B is undefined. Q27 Which
28、 of the following interfaces can be used to manage a collection of elements, with no duplication. 1) List 2) Vector 3) Set Q28 Which of the following statements are true regarding inner classes. 1) Variables defined inside inner classes cannot be static. 2) Variables defined inside inner classes can
29、not be static unless the inner class itself is static. 3) Non-static inner classes (which are not defined in a method) have access to all class and instance variables, regardless of the access qualifier of those variables. 4) An inner class can actually be a subclass of the outer class 5) Inner clas
30、ses can be declared as private. Top level, outer classes cannot. Q29 Which of the following are valid ways to define an abstract method. 1) abstract void Test(); 2) abstract void Test() 3) static abstract void Test(); 4) final abstract void Test(); 5) Methods cannot be defined as abstract, only vari
31、ables can be abstract. Q30 Consider the following: class A extends Integer int x = 0; Select all valid statements. 1) The code will compile correctly. 2) The code will not compile because Integer is final and cannot be subclassed. 3) The code will not compile because class A has no methods or constructor. 4) The code will compile
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1