?? 經典147題庫修正版(scjp考生必做).txt
字號:
4. public class AbstractTest extends AbstractIt {
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.
26
====
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.println(j);
12. }
13. }
What is the result?
A. Compilation will fail.
B. Compilation 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".
27
====
Given:
1. class super {
2. public 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) {retrun 4.0f; }
28
====
Which declaration prevents creating a subclass of an outer class?
A. static class FooBar{}
B. private class FooBar{}
C. abstract public class FooBar{}
D. final public class FooBar{}
E. final abstract class FooBar{}
29
====
Given:
1. byte [] arry1, array2[];
2. byte array3 [][];
3. byte[][] array4;
If each array has been initialized, which statement will cause a compiler 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
30
====
Given:
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 (String text) {
11. i = 2;
12. }
13.
14. public static void main (String args[]) {
15. Sub sub = new Sub ("Hello");
16. System.out.println(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 program will print "1".
D. Compilation will succeed and the program will print "2".
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. float
F. double
41
====
Given:
1. public class X {
2. public Object m () {
3. Object o = new Float (3.14F);
4. Object [] oa = new Object [1];
5. oa[0]= o;
6. o = null;
7. return oa[0];
8. }
9. }
When is the float object created in line 3, eligible for garbage collection?
A. Just after line 5
B. Just after line 6
C. Just after line 7 (that is, as the method returns)
D. Never in this method
42
====
Given:
3. String foo = "ABCDE";
4. Foo.substring(3);
5. Foo.concat("XYZ");
6.
Type the value of foo at line 6.
Ans:
43
====
Which method is an appropriate 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));
44
====
You need to store elements in a collection that guarantees that no
duplicates are stored and all elements can be accessed in natural order.
Which interface provides that capability?
A. java.util.Map
B. java.util.Set
C. java.util.List
D. java.util.StoredSet
E. java.util.StoredMap
F. java.util.Collection
45
====
Which statement is true for the class java.util.HashSet?
A. The elements in the collection are ordered.
B. The collection is guaranteed to be immutable.
C. The elements in the collection are guaranteed to be unique.
D. The elements in the collection are accessed using a unique key.
E. The elements in the collections are guaranteed to be synchronized.
46
====
Given:
1. public class IfTest {
2. public static void main(String[] args) {
3. int x = 3;
4. int y = 1;
5. if (x = y)
6. System.out.println("Not equal");
7. else
8. System.out.println("Equal");
9. }
10. }
What is the result?
A. The output is "Equal".
B. The output in "Not Equal".
C. An error at line 5 causes compilation to fall.
D. The program executes but does not print a message.
47
====
1. public class Test {
2. public static void main(String args[]) {
3. int i = 0;
4. while (i) {
5. if (i==4) {
6. break;
7. }
8. ++i;
9. }
10.
11. }
12.}
What is the value of i at line 10?
A. 0
B. 3
C. 4
D. 5
E. the code will not compile
48
====
Given:
3. int i = 1, j = 10 ;
4. do {
5. if (i++ > --j) continue;
6. } while (i<5);
After execution, what are the values for i and j?
A. i = 6 and j= 5
B. i = 5 and j= 5
C. i = 6 and j= 4
D. i = 5 and j= 6
E. i = 6 and j= 6
49
====
Given:
1. switch (i) {
2. default:
3. System.out.println("Hello");
4. )
What are the two acceptable types for the variable i? (Choose Two)
A. char
B. byte
C. float
D. double
E. Object
50
====
Given:
1. public class Foo {
2. public static void main (String[] args){
3. try {return;}
4. finally {System.out.println("Finally");}
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.
51
====
1. import java.io.IOException;
2. public class ExceptionTest{
3. public static void main (String[] args)
4. try {
5. methodA();
6. } catch (IOException e) {
7. System.out.println("Caught IOException");
8. } catch (Exception e) {
9. System.out.println("Caught Exception");
10. }
11. }
12. public void methodA () {
13. throw new IOException ();
14. }
15.}
What is the result?
A. The code will not compile.
B. The output is caught exception.
C. The output is caught IOException.
D. The program executes normally without printing a message.
52
====
1. public class Test {
2. public static String output = "";
3.
4. public static void foo(int i) {
5. try {
6. if(i == 1) {
7. throw new Exception ();
8. }
9. output += "1";
10. }
11. catch(Exception e) {
12. output += "2";
13. return;
14. }
15. finally {
16. output += "3";
17. }
18. output += "4";
19. }
20.
21. public static void main (String args[]) {
22. foo(0);
23. foo(1);
24.
25. }
26. }
What is the value of the variable output at line 24?
Ans:
53
====
Given:
1. public class Foo implements Runnable {
2. public void run (Thread t) {
3. System.out.println("Running.");
4. }
5. public static void main (String[] args) {
6. new Thread (new Foo()).start();
7. }
8. }
What is the result?
A. An exception is thrown
B. The program exists without printing anything
C. An error at line 1 causes compilation to fail.
D. An error at line 2 causes the compilation to fail.
E. "Running" is printed and the program exits
54
====
Which statement is true?
A. If only one thread is blocked in the wait method of an object,
and another thread executes the modify on that same object,
then the first thread immediately resumes execution.
B. If a thread is blocked in the wait method of an object,
and another thread executes the notify method on the same object,
it is still possible that the first thread might never resume execution.
C. If a thread is blocked in the wait method of an object,
and another thread executes the notify method on the same object,
then the first thread definitely resumes execution as a direct and sole consequence of the notify call.
D. If two threads are blocked in the wait method of one object,
and another thread executes the notify method on the same object,
then the first thread that executed the wait call first definitely resumes execution as a direct
and sole consequence of the notify call.
55
====
Which two CANNOT directly cause a thread to stop executing? (Choose Two)
A. Calling the yield method
B. Calling the wait method on an object
C. Calling the notify method on an object
D. Calling the NotifyAll method on an object
E. Calling the start method on another Thread object
56
====
Which two can be used to create a new Thread? (Choose Two)
A. Extend java.lang.Thread and override the run method.
B. Extend java.lang.Runnable and override the start method.
C. Implement java.lang.Thread and implement the run method.
D. Implement java.lang.Runnable and implement the run method.
E. Implement java.lang.Thread and implement the start method.
57
====
Given:
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 setXY(int i){setX(i); setY(i);}
7. public synchronized boolean check() {return x != y;}
8. }
Under which conditions will check () return true when
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -