D SortedSet会保证它的遍历是按natural ordering的

解决方案 »

  1.   

    test1 test2:

    Because static variable is not used by classed but objects.
      

  2.   

    You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be access in nature order, which interace provides that capability? 
     A. java.uil.Map 
     B.java.util.Set 
     C.java.util.List 
     D.java.util.SortedSet 
     E.java.util.SortedMap 
     F.java.util.Collection
    Answer:  B
    set为最佳答案。
      

  3.   

    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.
    Answer:  C
      

  4.   

    Given:
    1. package test1;
    2. public class Test1 {
    3. static int x = 42;
    4. }
    1. package test2;
    2. public class Test2 extends test1.Test1 {
    3. public static void main(String[] args) {
    4. System.out.printIn(“x = “ + x);
    5. }
    6. }
    What is the result?
    A. x = 0
    B. x = 42
    C. Compilation fails because of an error in line 2 of class Test2.
    D. Compilation fails because of an error in line 3 of class Test1.
    E. Compilation fails because of an error in line 4 of class Test2.
    Answer:  E
    Fault:x is not public in test1.Test1; cannot be accessed from outside package
      

  5.   

    test1 test2:

    Because static variable is not used by classed but objects.D没错吧,在class里面定义全局的静态变量没问题吧....应该是E
      

  6.   

    11. try {
    12. int x = 0;
    13. int y = 5 / x;
    14. } catch (Exception e) {
    15. System.out.println(“Exception”);
    16. } catch (ArithmeticException ae) {
    17. System.out.println(“Arithmetic Exception”);
    18. }
    19. System.out.println(“finished”);
    What is the result?
    A. finished
    B. Exception
    C. Compilation fails.
    D. Arithmetic Exception
    Answer:  C
    Fault:exception java.lang.ArithmeticException has already been caught
      

  7.   

    Which statement is true?
    A. The Error class is a runtimeException.
    B. No exceptions are subclasses of Error.
    C. Any statement that may throw an Error must be enclosed in a try block.
    D. Any statement that may throw an Exception must be enclosed in a try block.
    E. Any statement that may throw a runtimeException must be enclosed in a try
    block.
    Answer:D
      

  8.   

    Given:
    11. try {
    12. int x = 0;
    13. int y = 5 / x;
    14. } catch (Exception e) {
    15. System.out.println(“Exception”);
    16. } catch (ArithmeticException ae) {
    17. System.out.println(“Arithmetic Exception”);
    18. }
    19. System.out.println(“finished”);
    What is the result?
    A. finished
    B. Exception
    C. Compilation fails.
    D. Arithmetic ExceptionAnswer:  B
    Exception在ArithmeticException前面,Exception包含的集合最大,应该在这里就被catch住了......
      

  9.   

    Which statement is true?
    A. The Error class is a runtimeException.
    B. No exceptions are subclasses of Error.
    C. Any statement that may throw an Error must be enclosed in a try block.
    D. Any statement that may throw an Exception must be enclosed in a try block.
    E. Any statement that may thro a runtimeException must be enclosed in a try
    block.Answer:  E
      

  10.   

    Given:
    1. class Bar { }
    1. class Test {
    2. Bar doBar() {
    3. Bar b = new Bar();
    4. return b;
    5. }
    6. public static void main (String args[]) {
    7. Test t = new Test();
    8. Bar newBar = t.doBar();
    9. System.out.printIn(“newBar”);
    10. newBar = new Bar();
    11. System.out.printIn(“finishing”);
    12. }
    13. }
    At what point is the Bar object, created on line 3, eligible for garbage collection?
    A. After line 8.
    B. After line 10.
    C. After line 4, when doBar() completes.
    D. After line 11, when main() completes.
    Answer:B
    理由:我认为在这行,指向第三行创建的Bar 的对象的引用已经消失,可以进行垃圾收集。
      

  11.   

    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 13
    B. Line 14
    C. Line 18
    D. Line 20Answer:  B
    Line 14不可能走到......
      

  12.   

    1. class A {
    2. }
    3. class Alpha {
    4. private A myA = new A();
    5.
    6. void dolt( A a ) {
    7. a = null;
    8. }
    9. void tryIt() {
    10. dolt( myA );
    11. }
    12. }
    Which two statements are correct? (Choose two.)
    A. There are no instanced of A that will become eligible for garbage collection.
    B. Explicitly setting myA to null s that instance to be eligible for garbage collection.
    C. Any call on tryIt() causes the private instance of A to be ed for garbage
    collection.
    D. Private instances of A become eligible for garbage collection when instances of
    Alpha become eligible for garbage collection.
    Answer:BD
    C肯定是错的,按照sun官方的说法:当一个引用变量作为参数传递给一个方法时, 在这个方法内可以改变变量的值,即改变引用指向的对象,但是方法的调用结束后,改变量恢复原来的值,即变量仍然指向原来的对象。
      

  13.   

    题实在太多了,简单的说一下
    1 which interace provides that capability 选择D no duplicat->Set nature sorted->SortedSet
    2 Which statement is true for the class java.util.HashSet?
      我说不清楚其他答案,但是有HashSet的性质,D。UniqueKey访问肯定是对的,如果是多选,请自己查一下
    3 What is the result?
     选B X=42 因为X是父类的公共类变量,子类很自然的继承过来了。静态变量可以当作普通的变量使用,所以直接输出是可以的
    4 What is the result?
      选C 编译错误。因为当捕获了Exception后,其后面所有的子类就被屏蔽,不能再捕获了,所以编译器会认为后面的Catch子句无效,从而报错
    6 第五题第一个assert,第13行就出错,因为assert后应该是一个表达式,不可以是常量。这道题我不太熟悉,请另外的人发表意见
    7 选B,在第10行后,可以回收。因为第三行doBar方法创建的对象,只是被第八行的newBar变量引用。(注意,方法体内的b变量虽然也引用该对象,但b是局部变量,方法掉用结束后b就释放了),所以在第10行的newBar指向另一对象后,doBar方法创建的变量就没有人引用了,所以可回收
    8 选CD,都可以回收,只是一个孤岛现象,具体解答我在认证栏目的java考试版里做过了,请查阅帖子题目“我觉得这条关于垃圾回收的问题好困难耶~”
    9 选AD,当前A的实例不可回收,因为私有实例变量myA依然指向它。注意,doIt方法里只是将局部变量a设为null,并不影响myA,java里是按值传递。
    myA是Alpha的类变量,生命周期同Alpha类的实例,所以当该实例可以回收后,myA变量释放,从而这个A实例就可以回收了