Overriding static method with different static variable in java Suppose I have 3 classes, Animal, Dog, and Cat
public abstract class Animal {
    private static final List&lt;Animal&gt; allObjects = new ArrayList&lt;&gt;();
    
    public Animal(){
      allObjects.add(this);
    }
    
    // Returns immutable list of all Animal objects
    public static List&lt;? extends Animal&gt; getInstantiatedObjects(){
         return allObjects;
    }
}

public class Cat extends Animal {
    private static final List&lt;Cat&gt; allObjects = new ArrayList&lt;&gt;();
    
    public Cat(){
      super();
      allObjects.add(this);
    }
    
    // Returns immutable list of all Cat objects
    public static List&lt;? extends Cat&gt; getInstantiatedObjects(){
         return allObjects;
    } 
}

While this works, I can't help but think that this is poor design, and it would be better if either the static method would be inheritable and &quot;adapt&quot; to the class (? extends thisClass), or it raised an implementation error if the method wasn't implemented. For instance,
public class Dog extends Animal {
    private static final List&lt;Dog&gt; allObjects = new ArrayList&lt;&gt;();
    
    public Dog(){
      super();
      allObjects.add(this);
    }
    
    /* Returns immutable list of all Dog objects
    public static List&lt;? extends Dog&gt; getInstantiatedObjects(){
         return allObjects;
    } */
}

returns no errors and simply uses the static method of the superclass, but that doesn't allow the code to store only objects of its class or lower. Any help would be greatly appreciated!
From time to time one sees this wish. I never needed it, but the way is to have one global repository in the base class:
public abstract class Animal {
    private static final Map&lt;Class&lt;? extends Animal&gt;, List&lt;Animal&gt;&gt; all =
            new HashMap&lt;&gt;();

    protected Animal() {
        List&lt;Animal&gt; species = all.computeIfAbsent(getClass(),
                type -&gt; new ArrayList&lt;&gt;());
        species.add(this);
    }

    public static Stream&lt;T extends Animal&gt; all(Class&lt;T&gt; type) {
        return all.computeIfAbsent(getClass(), 
               type -&gt; new ArrayList&lt;&gt;()).stream().map(type::cast);
    }

Instead of storing the Animal child instance one could use a WeakReference&lt;Animal&gt; to let animals disappear when not used.
A call to Animal.all(Dog.class) needs no Animal instance.