πŸ“Š JAVA
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”)));
}

}
  • (A) 1 null
  • (B) 2 emp1 OVERRIDDEN
  • (C) 3 null
  • (D) 1 emp1 OVERRIDDEN
πŸ’¬ Discuss
βœ… Correct Answer: (C) 3 null

You must be Logged in to update hint/solution

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
178
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Uday Singh
Publisher
πŸ“ˆ
96%
Success Rate