How to call a different constructor based on variable value in Java
<p>Its a simple question really.</p>

<pre><code>class salad
class chef_salad extends salad
class ceasar_salad extends salad
</code></pre>

<p>So I have a variable <code>type</code> and I want to create the appropriate object based on type.</p>

<p>Apparently I can do</p>

<pre><code>if(type.equals("chef"){ salad s = new chef_salad(); }
</code></pre>

<p>I suppose I can even make that a static method that returns a <code>salad</code> object, but is this really the best approach or there is a better way to do it through constructors?</p>

<p>ps. fictional example</p>
