title: Call a concrete method on an concrete object which current type is an abstract object
body: <p>I have the following abstract class which ensures that all subclasses contain the method <code>eval()</code>.</p>
  
  <pre><code>public abstract class ExpressionTreeNode {
          abstract double eval();
  } 
  </code></pre>
  
  <p>I would like to create <strong>several</strong> concrete classes which inherit from ExpressionTreeNode, like the class <code>Addition</code>. Theses concrete classes contain two other concrete classes (<code>right</code> and <code>left</code>), which inherit from <code>ExpressionTreeNode</code>. Since there might be different concrete classes I defined the variable type as <code>ExpressionTreeNode</code>.</p>
  
  <p>Furthermore I would like to call the <code>eval()</code> method from these concrete classes. But Eclipse says at this point (e.g. <code>double arg1 = right.eval();</code>):</p>
  
  <blockquote>
    <p>The method eval() is undefined for the type ExpressionTreeNode</p>
  </blockquote>
  
  <p>Why is it undefined? There can't be a object which is only of the type <code>ExpressionTreeNode</code> and therefore it will contain the <code>eval()</code> method.</p>
  
  <pre><code>public class Addition extends ExpressionTreeNode {
  
      ExpressionTreeNode left;
      ExpressionTreeNode right;
  
      public double eval() {
          double arg1 = left.eval();
          double arg2 = right.eval();
  
          return arg1+arg2;
      }
  }
  </code></pre>
  
  <p>How can I solve this problem (without using an interface instead of the abstract class)?</p>