import java.util.*;
public class Group extends HashSet<Person>
{
public static void main(
String arg[])
{
Q12 g = new Q12();
g.add(new Person("Hans"));
g.add(new Person("Lotte"));
g.add(new Person("Jane"));
g.add(new Person("Hans"));
g.add(new Person("Jane"));
System.out.println("Total ::"+g.size());
System.out.println("contents............"+g);
}
public boolean add(Object o)
{
System.out.println("Adding ::"+o);
return super.add(o);
}
}
class Person
{
private final String name;
public Person(String name)
{
this.name= name;
}
public String toString()
{
return name;
}
}
ANSWER F is correct. The problem here is in Group's add() method�it should have been
add(Person), since the class extends HashSet<Person>. So this doesn't compile.
Pop Quiz: What would happen if you fixed this code, changing add(Object) to
add(Person)? Try running the code to see if the results match what you thought.
now my problem is that when I have done the appropriate changes and then run it again the Total is coming to be 5.But how is it possible as it is a set and a set not allow the duplicate entries........???
According to me the size should be 3.....
Please guide me..