Q. What will be the output of the following code –
Code:
import java. util.HashMap;
class newEmployee
{
private String name;
public newEmployee (String name)
{
this.name = name;
}
@Override
public int hashCode()
{
return 1;
}
}
class EmployeeClass
{
public static void main(String args[])
{
HashMap hm=new HashMap();
hm.put(new newEmployee(“a”),”emp1″);
hm.put(new newEmployee(“b”),”emp2″);
hm.put(new newEmployee(“a”),”emp1 overridden”);
System.out.println(hm.size());
System.out.println(hm.get(new newEmployee(“a”)));
}
}
β
Correct Answer: (C)
3 null