1) Yes, 10 separate objects are created. However, they are not accessible outside the loop because A is declared in the loop. Even if A was declared outside the loop, it can only point to one object at a time. So only the last one would be accessible.
2) Yes, you need to store them in a list/array.
So they are separate objects, but only one is accessible.
First, I'd like to clarify some terminology. "Foo(int id)" isn't an object. It *could* be the header for a constructor of a class, however:
Also notice that the above code does not have any objects at all. It defines a class with a constructor. Think of a class as an outline for creating an object. It defines the state with member variables and what can be done with objects of the class with member methods.
An object on the other hand is an instance of a class. You can create an object similar to what you gave above:
Here "bar" is the name of a reference to an object that was created from class Foo. We also say that the object has type Foo. Strictly speaking it is not correct to say that the object is named.
To create 10 different objects (and keep references to all of them), you need an array:
To use the elements of this array, you need to use array subscripting:
I hope this helps to answer your question. I suggest that you look up more information on arrays on the Internet or in a textbook.