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 = new HashMap<>();

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

You might also like to view...

A ________ is a unit of data representing one character

A) megabyte B) terabyte C) byte D) bit

Computer Science & Information Technology

How can you work with keyboard arrow buttons?

What will be an ideal response?

Computer Science & Information Technology