Java dynamic object creation

Associate
Joined
26 Jan 2006
Posts
1,502
Hello,

I am coding a small applet and I want to create object dynamically.

lets say I got a class of animal I can create one by:

animal dog = new animal();

However, I want to create as many dogs I like (the user) through the button listeners.

How you can do this and keep track of (or set to your preference) the new object(s) name?

Thanks!
 
ArrayList myAnimals;

myAnimals.add(new animal());

like this?

edit:

got it thanx

ArrayList myAnimals = new ArrayList();
myAnimals.add(new animal());
 
Last edited:
Back
Top Bottom