Tworzenie listy instancji różnych obiektów i używanie tych obiektów

Kod Java:

import java.util.ArrayList;
import java.util.List;

class apple{
int price;

public void myFunction(int iPrice)
{
    price=iPrice;
}
}

class orange{
int price;

public void myFunction(int iPrice)
{
    price=iPrice;
}
}

public class main {

public static void main(String[] args) {
    List <Object> list= new ArrayList<>();

    //create 3 apple object to list
    list.add( new apple() );
    list.add( new apple() );
    list.add( new orange() );

    list.get(0). /* "get(0)." this isn't using apple object and my function */

}
}

questionAnswers(4)

yourAnswerToTheQuestion