Giving extending classes a specific behaviour?
<p>How can I have several extensions of a class <code>Fruit</code>, and based on what class/type the object ist, execute the same method on this fruit but with different function?</p>

<p>Example: I'm using a  <code>FruitManager</code> to add a new <code>Fruit fruit = new Apple();</code> to the fruitstore. If this fruit is an apple, I want of course to add this to the apples list. Elso to bananas list.
Now if I have 10 sorts of fruits, I do no want to create 10 functions like <code>addBanana()</code>, <code>addApple()</code> and so on.
And I too do not want to have cluttering if-else statements for getting the right fruit list.</p>

<p>Can I samehow get the fruitlist just based on the type of object I'm adding?</p>

<pre><code>class Fruit;
class Apple extends Fruit;
class Banana extends Fruit;

class FruitStore {
    List&lt;Fruit&gt; apples = new ArrayList&lt;Apple&gt;();
    List&lt;Fruit&gt; bananas = nwe ArrayList&lt;Banana&gt;();
}

class FruitManager {
    FruitStore store;

    //called from somewhere with Fruit fruit = new Apple();
    addFruit(Fruit fruit) {
        //how could things like this be done in one statement?
        store.&lt;get list apples or bananas&gt;.add(fruit);
    }
}
</code></pre>
