【WEEK】SCJP考试例题
weeksky吧
全部回复
仅看楼主
level 6
weeksky 楼主
Location: ... > Declarations and Access Control > Objective 1.1 > Item 1 Which three are legal array declarations? (Choose three.)A int [42] x; B int x [42]; C int [] x = (1,2,3); D char [] myChars; E int [] x = new int[] {2,4,5}; F int [] myScores []; Answer:Options D, E, and F are the correct answers.
2007年05月11日 06点05分 1
level 6
weeksky 楼主
Which two can be overridden? (Choose two.)A native void methoda(); B final void methoda() {} C void final methoda() {} D synchronized void methoda() {} E synchronized final void methoda() {} Answer:Options A and D are the correct answers. Final methods can not be overridden.
2007年05月11日 06点05分 2
level 6
weeksky 楼主
//Given: Test211class Test211 {static boolean b;public static void main(String [] args) {int x=0; if (b ) {x=1;}else if (b = false) {x=2;}else if (b) {x=3;}else {x=4;}System.out.println("x = " + x);}} /*What is the result?A x = 0 B x = 1 C x = 2 D x = 3 E x = 4 F Compilation fails *//*Answer:Option E is the correct answer. The instance variable b is initialized to false, reset to false on line 8 and falls through to line 15, where x is set to 4.*/
2007年05月11日 06点05分 3
level 6
weeksky 楼主
How can you destroy an object?A null all the references to the object B call Runtime.getRuntime().gc C set all of the object's references to null D call x.remove() , where x is the object's name E call x.finalize() , where x is the object's name F only the garbage collection system can destroy an object Answer:Option F is the correct answer. You can request that an object be destroyed, but only the GC decides when is actually destroyed.
2007年05月11日 06点05分 4
level 6
weeksky 楼主
Given:1. public class X {2. public void main(String [] args) {3. System.out.println("brand " + args[0]);4. }5. }And command line invocation:java X YWhat is the result?A brand B brand X C brand Y D brand X Y E Compilation fails F An exception is thrown at runtime Answer:Option F is the correct answer. The main() method that starts a Java program running must be declared static in addition to public and void.
2007年05月11日 06点05分 5
level 6
weeksky 楼主
Given:10. int i=3, j=0, result=1;11. result += i-- * --j ;12. System.out.println( result );What is the result?A 0 B -1 C -2 D -3 E Compilation fails F An exception is thrown at runtime Answer:Option C is the correct answer. Resolves to (i * (j-1) ) + 1
2007年05月11日 06点05分 6
level 6
weeksky 楼主
Given:10. class A {}11. class B {12. private A myA = new A();13. }Which two statements are true about the relationship between class A and class B? (Choose two.)A A maintains no relationship with B B B maintains no relationship with A C B maintains a "one to many" relationship with A D The relationship can be described with a has-a clause E The relationship can be described with an is-a clause Answer:Options A and D are the correct answers.Reference:The Java Programming Language, Third Edition, by Arnold, Gosling & Holmes, Chapter 3: Extending ClassesISBN: 0-201-70433-1
2007年05月11日 06点05分 7
level 6
weeksky 楼主
public class Test711{public static void main( String[] args ) {class T1 extends java.lang.Thread{}class T2 extends T1{}class T3 implements java.lang.Runnable{}new T1().start();new T2().start();new Thread(new T3()).start();System.out.println( "Executing" );} }/*What is the result?A Compilation fails. B The program never terminates. C The program runs with no output. D An exception is thrown at runtime. E The program outputs Executing and then terminates. F The program terminates after the third thread is created. *//*Option A is the correct answer. Compilation failure, T3 does not implement the interface Runnable and is therefore abstract and cannot be instantiated*/
2007年05月11日 06点05分 8
level 6
weeksky 楼主
public class Test811 {public static void main(String [] args) {double num = 7.4; int a = (int) Math.abs(num + .5);int b = (int) Math.ceil(num + .5);int c = (int) Math.floor(num + .5);int d = (int) Math.round(num + .5);int e = (int) Math.round(num - .5);int f = (int) Math.floor(num -.5);int g = (int) Math.ceil(num -.5);int h = (int) Math.abs(num - .5);System.out.println("" + a + b + c + d + e + f + g + h);}} /*What is the result?A 56 B 78787676 C 78788777 D 77787776 E Compilation fails. F An exception is thrown at runtime. *//*Option B is the correct answer. Math.abs returns the absolute of a number. Math.ceil returns the smallest double that is greater than or equal to the number, and also rounds it to the nearest integer. Math.floor returns the largest double that is less than or equal to the number, and rounds it to the nearest integer. Math.round returns the integer that is closest to the number, by adding .5 to the number and then truncating to get the nearest integer. Option "A" would be the correct answer if the System.out.println() statement had not included the "", since that would cause the integer variables to be arithmetically added rather than concatenated as String values.*/
2007年05月11日 06点05分 9
level 6
weeksky 楼主
Which three are true for class java.util.ArrayList? (Choose three.)A It can contain duplicates B Its methods are thread-safe C Can be iterated bi-directionally D It implements java.util.Set E It is well-suited for fast random access F It implements java.util.Collections Answer:Options A, C, and E are the correct answers. The Set interface does not permit duplicate elements, but since ArrayList implements List and not Set, it can hold duplicates. Its methods are not synchronized, so it's not thread-safe on its own. List classes use a ListIterator rather than a simple Iterator, because a ListIterator lets you traverse bi-directionally. It is well-suited for fast random access, and implements the RandomAccess interface. It also implements java.util.Collection (not Collections with an 's').
2007年05月11日 06点05分 10
level 2
可以借鉴和学习!并通过考试!
2007年05月14日 01点05分 11
1