I'm a beginner to Java. I need to create an array of objects. I have a class called child and a method to assign the age of a child. Then in my main method i want to create an array of child objects and assign a random age to each object in the array. How do you create an array that contains child objects?
I've tried things like:children [i] = new child();
but i can't get it to work! Any help would be appreciated.
Regards, James

isn't is something like children[] = new child[i];
Chi
They mostly come at night...mostly
I think it's the same as it is in C#:
child[] children = new child[i];or the 2 line version:
child[] children;
children = new child[i];-SN
yeah, that's what i meant. child[] children = new child[i];
They mostly come at night...mostly
hi james solution is
child [] children=new child[5];
classname[] arrayname=new classname[no of objects];
then u writechild[0]=new child(23);
classname[objectnumber]=new classname(age);child(23) is a parameterized construtor of class child.
this should solve ur problem...
do let me know when ur done
Aman
