U

Uday Singh • 7.23K Points
Tutor III

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<newEmployee,String> hm=new HashMap<newEmployee,String>();
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”)));
}

}
  • (A) 1 emp1 OVERRIDDENQ
  • (B) 2 emp1 OVERRIDDEN
  • (C) 1 null
  • (D) 3 null
  • Correct Answer - Option(A)
  • Views: 115
  • Filed under category JAVA

No solution found for this question.
Add Solution and get +2 points.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.


Question analytics