【WEEK】SCJP考试真题1-5题
weeksky吧
全部回复
仅看楼主
level 6
weeksky 楼主
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 = 29. }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:1. class TestA {2. TestB b;3. TestA() {4. b = new TestB(this);5. }6. }7. class TestB {8. TestA a;9. TestB(TestA a) {10. this.a = a;11. }12. }13. class TestAll {14. public static void main (String args[]) {15. new TestAll().makeThings();16. // ...code continues on17. }18. void makeThings() {19. TestA test = new TestA();20. }21. }Which two statements are true after line 15, before main completes? (Choose two)A. Line 15 causes a stack overflow.B. An exception is thrown at runtime.C. The object referenced by a is eligible for garbage collection.D. The object referenced by b is eligible for garbage collection.E. The object referenced by a is not eligible for garbage collection.F. The object referenced by b is not eligible for garbage collection.Answer: C, F.Q4.Given:11. public class Test {12. public void foo() {13. assert false;14. assert false;15. }16. public void bar(){17. while(true){18. assert false;19. }20. assert false;21. }22. }What causes compilation to fail?A. Line 13B. Line 14C. Line 18D. Line 20Answer: B.Q5.Which statement is true about assertion in the Java programming language?A. Assertion expressions should not contain side effects.B. Assertion expression values can be any primitive type.C. Assertion should be used for enforcing preconditions on public methods.D. An AssertionError thrown as a result of a failed assertion should always be handled bythe enclosing method.Answer: A.
2007年05月11日 06点05分 1
level 6
weeksky 楼主
转载或者学习的同学!需要后面的题请留下你的邮箱便于我发给你!本人每周将发5道题,请吧友及时关注!
2007年05月11日 13点05分 2
level 6
weeksky 楼主
D
2007年05月14日 00点05分 3
1