tulong2

1.2K 0 0
                                    

Options A and E are the correct syntax to handle all three types of Lists in the

takeCars argument

58.

Given:

1. import java.util.*;

2. class Stuff implements Comparable {

3. int x;

4. Stuff(int x) { this.x = x; }

5. public int compareTo(Object o) { return 0; }

6. }

7. class AddStuff {

8. public static void main(String [] args) {

9. TreeSet<Stuff> ts = new TreeSet<Stuff>();

10. ts.add(new Stuff(1));

11. ts.add(new Stuff(2));

12. System.out.println(ts.size());

13. } }

What is the result?

A) 0

B) 1

C) 2

D) Compilation fails.

E) An exception is thrown at runtime.

Answer:

Option B is correct. Since compareTo always returns 0, the second add fails because

TreeSets cannot have duplicate entries.

59.

Given:

1. import java.util.*;

2. class DumpMap {

3. public static void main(String [] args) {

4. HashMap h = new HashMap();

5. h.put("a","aa"); h.put("b","bb"); h.put("c","cc");

6. Set ks = h.keySet();

7. Object [] ka1 = ks.toArray();

8. ks = new TreeSet(ks);

9. Object [] ka2 = ks.toArray();

10. System.out.println(Arrays.equals(ka1, ka2));

11. }

12. }

What is the result?

A) true

B) false

C) The output is unpredictable.

D) Compilation fails due to an error on line 8.

Answer:

Option C is correct. ka2 is sorted, but there is no guarantee what order ka1's

elements are in.

60.

Given two files.

1. package x;

2. public class X {

3. // insert code here

4. }

and.

1. package x;

2. public class Find4 {

3. public static void main(String [] args) {

4. X myX = new X();

5. myX.doX();

6. }

7. }

Naabot mo na ang dulo ng mga na-publish na parte.

⏰ Huling update: Jun 23, 2010 ⏰

Idagdag ang kuwentong ito sa iyong Library para ma-notify tungkol sa mga bagong parte!

tulong2Tahanan ng mga kuwento. Tumuklas ngayon