Saturday, August 21, 2010

Maps: GPS.java

Courtesy of Sun Web Learning Center

1. import java.util.*;
2.
3. class GPS {
4.   public static void main(String [] args) {
5.     // insert code here
6.     c.put("myKey", 42);
7.   }
8. }

Which three, inserted independently at line 5, allow the code to compile? (Choose three.)


A     Map c = new SortedMap();
B     HashMap c = new HashMap();
C     SortedMap c = new TreeMap();
D     HashMap c = new Hashtable();
E     Map c = new LinkedHashMap();
F     ArrayList c = new ArrayList();

B, C, and E are correct. SortedMaps are abstract, Hashtable does NOT implement HashMap, and ArrayList is not a map.

No comments:

Post a Comment