单项选择题

11. public static void append(List list) { list.add(”0042”); } 
12. public static void main(String[] args) { 
13. List intList = new ArrayList(); 
14. append(intList); 
15. System.out.println(intList.get(0)); 
16. } 
What is the result?() 

A. 42
B. 0042
C. An exception is thrown at runtime.
D. Compilation fails because of an error in line 13.
E. Compilation fails because of an error in line 14.


您可能感兴趣的试卷

你可能感兴趣的试题

1.多项选择题

1. import java.util.*; 
2. public class Test { 
3. public static void main(String[] args) { 
4. List strings = new ArrayList(); 
5. // insert code here 
6. } 
7. } 
Which four, inserted at line 5, will allow compilation to succeed?()

A. String s = strings.get(0);
B. Iterator i1 = strings.iterator();
C. String[] array1 = strings.toArray();
D. Iterator i2 = strings.iterator();
E. String[] array2 = strings.toArray(new String[1]);
F. Iterator i3 = strings.iterator();

3.多项选择题Which two statements are true about the hashCode method?()

A. The hashCode method for a given class can be used to test for object equality and object inequality for that class.
B. The hashCode method is used by the java.util.SortedSet collection class to order theelements within that set.
C. The hashCode method for a given class can be used to test for object inequality, but NOT object equality, for that class.
D. The only important characteristic of the values returned by a hashCode method is that the distribution of values must follow a Gaussian distribution.
E. The hashCode method is used by the java.util.HashSet collection class to group the elements within that set into hash buckets for swift retrieval.

4.单项选择题

1. public class Person { 
2. private String name; 
3. public Person(String name) { this.name = name; } 
4. public boolean equals(Person p) { 
5. return p.name.equals(this.name); 
6. } 
7. } 
Which is true?() 

A. The equals method does NOT properly override the Object.equals method.
B. Compilation fails because the private attribute p.name cannot be accessed in line 5.
C. To work correctly with hash-based data structures, this class must also implement the hashCode method.
D. When adding Person objects to a java.util.Set collection, the equals method in line 4 will prevent duplicates.

5.单项选择题

public class Person { 
private name; 
public Person(String name) { 
this.name = name; 
} 
public boolean equals(Object o) { 
if( !o instanceof Person ) return false; 
Person p = (Person) o; 
return p.name.equals(this.name); 
} 
} 
Which is true?() 

A. Compilation fails because the hashCode method is not overridden.
B. A HashSet could contain multiple Person objects with the same name.
C. All Person objects will have the same hash code because the hashCode method is not overridden.
D. If a HashSet contains more than one Person object with name=”Fred”, then removing another person, also with name=”Fred”, will remove them all.

10.单项选择题

1. import java.util.*; 
2. public class TestSet { 
3. enum Example { ONE, TWO, THREE } 
4. public static void main(String[] args) { 
5. Collection coll = new ArrayList(); 
6. coll.add(Example.THREE); 
7. coll.add(Example.THREE); 
8. coll.add(Example.THREE); 
9. coll.add(Example.TWO); 
10. coll.add(Example.TWO); 
11. coll.add(Example.ONE); 
12. Set set = new HashSet(coll); 
13. } 
14. } 
Which statement is true about the set variable on line 12?() 

A. The set variable contains all six elements from the coll collection, and the order is guaranteed to be preserved.
B. The set variable contains only three elements from the coll collection, and the order is guaranteed to be preserved.
C. The set variable contains all six elements from the coil collection, but the order is NOT guaranteed to be preserved.
D. The set variable contains only three elements from the coil collection, but the order is NOT guaranteed to be preserved.