Vote count:
0
Hi I was wondering if it is possible to create an array of objects including superclass and subclass? I am sure many people have at least thought of this possibility. I am new to polymorphism so perhaps my understanding is off in my logic, but to my current knowledge the object creation is correct.
Design a new class called PersonTest with a main method that defines a PersonData object and a PersonLocation object (both without arguments) and two more objects with arguments and store all the objects in an Array for retrieval and modification of instantiated objects (i.e. Array of Objects).
This is what I did for creating the two objects without and with arguments.
PersonLocation personLocation = new PersonLocation();
PersonData personData = new PersonData();
PersonLocation personLocationOverloaded = new PersonLocation("Hamilton");
PersonData personDataOverloaded = new PersonData("Stirling","905-768-5676");
I tried many different ways to create this array with no luck. I tried a for loop with a regular array. I tried an arrayList(Not professional at this).
I am starting to think what is asked in the question mentioned above is not possible and I am actually suppose to create two different array of objects. However if it is possible I am sure many programmers as well as myself would be interested in expanding our knowledge of polymorphsim and arrays of objects.
Thanks,
Aucun commentaire:
Enregistrer un commentaire