title: Casting from undetermined subclass to superclass
body: <p>So in the following example I have an abstract super class with two subclasses. I want the method <strong>someMethod</strong> to return an object of type <strong>otherclass</strong> and then I will cast it to <strong>someSuperClass</strong>. How can I create a new instance of an object of the same type as <strong>otherclass</strong>? I would like to avoid having it be an abstract method and then defining it in each subclass.</p>
  
  <pre><code>public abstract class SomeSuperClass {
      public SomeSuperClass() {
      }
  
      public SomeSuperClass someMethod(SomeSuperClass otherClass) {
          return (SomeSuperClass) ????
      }
  }
  
  public class SomeSubClass extends SomeSuperClass {
      public SomeSubClass() {
          super();
      }
  }
  
  public class SomeOtherSubClass extends SomeSuperClass {
      public SomeOtherSubClass() {
          super();
      }
  }
  </code></pre>
  
  <p>Edit:</p>
  
  <p><strong>otherClass</strong> is a parameter/object that is of type <strong>SomeSubClass</strong> or <strong>SomeOtherSubClass</strong>.</p>