<< December 16, 2008 | Home | December 18, 2008 >>

Wednesday Java Quiz

(Mark Volkmann suggested this quiz.)

Q: Will the following Java source compile, run without exceptions?

import java.util.SortedMap; 
import java.util.TreeMap; 
 
public class Main { 
    public static void main(String[] args) { 
        SortedMap sm = new TreeMap(); 
        sm.put("one", 1); 
        sm.put(2, "two"); 
 
        System.out.println("value for one is " + sm.get("one")); 
        System.out.println("value for 2 is " + sm.get(2)); 
    } 
}

Strict rules: No actually running the Java compiler.