Originally posted by brian39:
and would the object numb be added each position in the arraylist be ok or would the object need to be named something else since it is a reference and all the numbs in the arraylist would point to the same object?*/
Your code is fine.
numb is a reference to an object. When you call
you add a copy of that reference to the ArrayList, so you now have two references to the same object (numb and the first element in the ArrayList). The next time round the loop, when
is executed, numb will now point to the new object and the first element of the ArrayList will still point to the first object you created. You then call
again. You now have two references to the second object you created (numb and the second element of the ArrayList) and one reference to the first object you created (the first element of the ArrayList) and so on and so on.