A

Admin • 802.91K Points
Coach

Q. What will be the output of the following code –

Code:
import java.util.HashMap;
public class Employee {
private String name;

public Employee(String name)
{
this.name = name;
}
}

class EmployeeClass
{
public static void main(String args[])
{
HashMap<Employee,String> hm=new HashMap<Employee,String>();
hm.put(new Employee(“a”),”emp1″);
hm.put(new Employee(“b”),”emp2″);
hm.put(new Employee(“a”),”emp1 overridden”);

System.out.println(hm.size());
System.out.println(hm.get(new Employee(“a”)));
}

}
  • (A) Compile time exception
  • (B) a b c d e 1
  • (C) 3 null
  • (D) None
  • Correct Answer - Option(C)
  • Views: 2
  • Filed under category Java
  • Hashtags:

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.