If I create an Array in the class DefaultItems:
DefaultItems[] items = new DefaultItems[20];
I want to use this as a storage array for 5 different class objects. I want to store a Car object, Person object and Pet object.
DefaultItems[1] = Car Object;
DefaultItems[2] = Person Object;
Is this possible?
If
CarandPersonderive fromDefaultItemsthen your code should work (assuming the typos are fixed).If the classes are not related in any way then you can achieve what you want by using
Object[]instead ofDefaultItems[]. All classes derive fromObject.