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
πŸ’¬ Discuss
βœ… Correct Answer: (C) 3 null

You must be Logged in to update hint/solution

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
229
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Mr. Dubey
Publisher
πŸ“ˆ
95%
Success Rate