
Q1.
Given:
1. package foo;
2.
3. import java.util.Vector;
4.
5. private class MyVector extends Vector {
6. int i = 1;
7. public MyVector() {
8. i = 2
9. }
10. }
11.
12. public class MyNewVector extends MyVector {
13. public MyNewVector() {
14. i = 4;
15. }
16. public static void main(String args[]) {
17. MyVector v = new MyNewVector();
18. }
19. }
What is the result?
A. Compilation succeeds.
B. Compilation fails because of an error at line 4.
C. Compilation fails because of an error at line 5.
D. Compilation fails because of an error at line 14.
E. Compilation fails because of an error at line 17.
Answer: B.
Q2.
Given:
12. void start() {
13. A e = new A();
14. B b = new B();
15. a.s(b);
16. b = null;
17. a = null;
18. System.out.printIn(“start completed”);
19. }
When is the B object, created in line 14, eligible for garbage collection?
A. After line 16.
B. After line 17.
C. After line 18 (when the methods ends).
D. There is no way to be absolutely certain.
E. The object is NOT eligible for garbage collection.
Answer: C.
Q3.
Given:
评论0