What will be the output of the following program?
import java.util.HashMap;
import java.util.Map;
public class Program {
public static void main(String... args) {
Key k1 = new Key();
Key k2 = new Key();
Map
map.put(k1, "value1");
map.put(k2, "value2");
System.out.println(map.get(k1));
System.out.println(map.get(k2));
}
}
class Key {
public int hashCode() {
return 1;
}
}
a. value1
value2
b. null
null
c. value2
value2
d. A Runtime Exception will be thrown.
a. value1
value2
It doesn't matter that hashCode returns a constant value.
Computer Science & Information Technology