Java subclass methods are not overriding despite explicit use of @Override : <p>I am trying to make an abstract algorithm class for informed search with different heuristics. My idea was to have different subclasses overwrite the default heuristic() method, but the dynamic binding seems not to be working when I call the subclasses.</p>

<p>In <strong>astar.java</strong>:</p>

<pre><code>public interface Astar {
    abstract String heuristic();
}
</code></pre>

<p>In <strong>search.java</strong></p>

<pre><code>public class Search implements Astar {
    public String heuristic() { return "default heuristic"; }
}
</code></pre>

<p>In <strong>EuclidianSearch.java</strong>:</p>

<pre><code>public class EuclidianSearch extends Search {
    @Override
    public String heuristic() { return "Euclidian"; }
}
</code></pre>

<p>In <strong>ChebyshevSearch.java</strong>:</p>

<pre><code>public class ChebyshevSearch extends Search {
    @Override
    public String heuristic() { return "Chebyshev"; }
}
</code></pre>

<p>In <strong>main.java</strong>:</p>

<pre><code>EuclidianSearch e_search = null; ChebyshevDistance ch_search = null;
Search[] SearchObjects = {e_search, ch_search};

for(Search so : SearchObjects) {
    System.out.println(so.heuristic());
}
</code></pre>

<p>When run, it displays:</p>

<pre><code>default heuristic
default heuristic
</code></pre>

<p>I define the array in terms of <code>Search</code> so I can be flexible: eventually, I want to have five or more different heuristics. Why doesn't the <code>heuristic()</code> method of the subclass override that of the superclass?</p>
