title: how to return different type from same function using inhertinace?
body: <p>for example, I want to create a parent class Node, and subclasses IntegerNode and CharacterNode.
  and try to find if a value already exists in a list without knowing what the type of values are.
  for that, I will send my Node object and during runtime, I want to get the appropriate value.</p>
  <p>there is a way to do that without using an instance of?</p>
  <pre><code>public class CharNode extends Node {
  
      private Character charNode;
  
      CharNode(char digit){
          this.charNode = digit;
      }
      
      Character getValue(){
          return charNode;
      }
  }
  
  
  public class IntegerNode extends Node {
      private Integer integerNode;
  
      IntegerNode(int number){
          this.integerNode = number;
      }
  
      Integer getValue(){
          return integerNode;
      }
  }
  
  
  
  public class Node {
  
      Node getNode();
  }
  
  
  
  
    boolean isExists(List&lt;Node&gt; list, Node value){
     ///// Here I want to check if the value inside the node already exists in that list without checking the type. It can be Lists of characters or a list of integers.
  
  }
  </code></pre>