My question is: how do you create an object without having a name for it already programmed? Does it even need to have a unique name,
since it would be stored in a seperate index and/or arraylist?
The answer to this is that you simply cannot create two separate objects using the same reference variable.
e.g. If you were to do this:
The compiler would simply tell you that the reference variable c
has already been defined.
However you can do something like this:
In this case the reference variable c
points to a new object on the heap and the object that it was first referencing gets garbage collected.
If you want to use an array of Contacts
, you can simply declare an array of whatever size you want and then intialize the variable using a loop.