Returning an abstract class from multiple inherited classes
<p>I'm trying to do the following:</p>

<pre><code>abstract class G {
    protected var = 0;
}

class G1 extends G {
    var = 1;
}

class G2 extends G {
    var = 2;
}

// This is where I'm having a problem
public G method() {
    switch(someVar) {
        case x:
            return new G1();
        case y:
            return new G2();
    }
 }
</code></pre>

<p>Java is complaining that method must return a type of G.  How should I go about returning G1 OR G2 (which both extend G)?  It very well may be that I'm approaching this entirely wrong...</p>

<p>Thank you.</p>
