dimanche 27 mars 2016

Java- Declare an object of a type chosen by the user

I don't know if this is possible, but what I'd like to know is the following:

Let's say I have an array which contains 2 different class type:

Fruit[] fruit;
fruit[0]= new Banana();
fruit[1]= new Apple();

What I want to do is this:

Fruit unknown= new fruit[0].getClass();

I want to declare an object of a type which is chosen by the user. Can I do it?





Aucun commentaire:

Enregistrer un commentaire