A
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”)));
}
}
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”)));
}
}
- Correct Answer - Option(C)
- Views: 2
- Filed under category Java
- Hashtags:
Discusssion
Login to discuss.