Java OCA OCP Practice Question 1220

Question

Given:

 3. import java.util.*;
 4. public class Main {
 5.   public static void main(String[] args) {
 6.     TreeMap<String, String> myMap = new TreeMap<String, String>();
 7.     myMap.put("a", "apple"); myMap.put("d", "date");
 8.     myMap.put("f", "fig"); myMap.put("p", "pear");
 9.     System.out.println("1st here: " +   // sop 1
10.       myMap.higherKey("f"));
11.     System.out.println("1st here: " +   // sop 2
12.       myMap.ceilingKey("f"));
13.     System.out.println("1st here: " +   // sop 3
14.       myMap.floorKey("f"));
15.     SortedMap<String, String> sub = new TreeMap<String, String>();
16.     sub = myMap.tailMap("f");
17.     System.out.println("1st here: " +   // sop 4
18.       sub.firstKey());/*from  w w  w.ja  va 2s.  c  o m*/
19.   }
20. }

Which of the System.out.println statements will produce the output 1st here: p?

Choose all that apply.

  • A. sop 1
  • B. sop 2
  • C. sop 3
  • D. sop 4
  • E. None; compilation fails
  • F. None; an exception is thrown at runtime


A is correct.

Note

The ceilingKey() method's argument is inclusive.

The floorKey() method would be used to find keys before the specified key.

The firstKey() method's argument is also inclusive.




PreviousNext

Related