I have three classes: apples, peaches and bananas. They all extend fruit. So I create them like:
Apple apple = Apple() ...
and then I would like to store them in a list.
List<Fruit> fruits = [apple, peach, banana]
Now I want to know the taste of the first list entry. So I might consider calling fruits.getTaste().
Do I get a correct answer here? Or does the list element not know that it has to call apples getTaste and calls the one of Fruit which can't answer correctly of course. So is the list element an apple or a fruit?
I hope it is clear what I mean. And if so, is there a typical way of solving problems like this?
Thank you very much.