Brainteaser: Broken Case of Inheritance

Consider the following case of inheritance:

public class ExtendingHashSet<E> extends HashSet<E>  {
   private int counter = 0;

   public ExtendingHashSet() {

   }

   @Override
   public boolean add(E e)  {
      counter++;
      return super.add(e);
   }

   @Override
   public boolean addAll(Collection&lt;? extends E&gt; c)  {
      counter += c.size();
      return super.addAll(c);
   }

   public int getCounter()  {
      return counter;
   }
}

Created instance:

ExtendingHashSet<String> s = new ExtendingHashSet<String>();
s.addAll(Arrays.asList("one", "two", "three"));

Question: What value would s.getCounter() method return at this point and why?

Looking forward for your answers dear readers

More from Alexander Zagniotov:

  1. Brainteaser: Broken Comparator
    Question: The following program returns result “1″, which indicates that first Integer value is greater than the second, why? Please...
  2. Multiple Return Statements
    Yesterday I had a thought in my mind (which is good already to have one) – how many return statements...
  3. Bitwise Operation In Hibernate 3
    Hi all… i encountered a small problem in doing bitwise operations with hibernate. Until now, HIbernate 2 HQL parser has...
  4. Java Generics and Reflection
    Hi, the other day I had a situation, where in my code at run time I had to determine the...
  5. JBoss Clustering – HASingleton Service
    Have you ever dealt with clustered singleton service? How to determine which cluster node is the master? Well, if I...