Java OCA OCP Practice Question 2843

Question

Given the proper import statement(s) and given:

4.     Map<String, String> h = new Hashtable<String, String>();   
5.     String[] k = {"1", "2", "3", null};  
6.     String[] v = {"a", "b", null, "d"};  
7.  
8.     for(int i=0; i<4; i++) {  
9.       h.put(k[i], v[i]);  
10.       System.out.print(h.get(k[i]) + " ");  
11.     }  
12.     System.out.print(h.size() + " " + h.values() + "\n"); 

What result is most likely?

  • A. Compilation fails.
  • B. "a b d 3 [b, d, a]"
  • C. "a b null d 3 [b, d, a]"
  • D. "a b null d 4 [b, d, null, a]"
  • E. "a b", followed by an exception.
  • F. "a b null", followed by an exception.


E is correct.

Note

A Hashtable does NOT allow any null keys OR null values.




PreviousNext

Related