firstly hello to you all..
Secondly, im new(ish) to java and prone to doing silly things so i'm probably doing it all wrong BUT
I want to be able to have a class that has as one of its members as an array of objects.
When the class is instanced I want the constructor to assign values to each of the items in the array, using a method of the class in the array.
Like
(for now I only need a fixed number of elements in the array)
class MyClass extends otherClass {
public MyClass (x,y,w,h) {
super(x,y)
...etc other constructor stuff
array[0].objectMethod(x,y);
array[1].objectMethod(x+(2*w),y);
... etc for the other array members
}
//Then a Get method for the data
public ObjectType getArray(idx) {
return array[idx];
}
//Declare the class data member like this ??
private ObjectType array[];
}
That's the general form I want BUT as the "ObjectType" object has not been created I cant call the method to add the members to the array?
Would I do something like.. ObjectType myType = new ObjectType[3];
before calling the methods of the array members? but if so where and how could I call MyClass.getArray(x)
??
I have tried searching/googling but cant find the right words to use in my search, any help would be appreciated...
many thanks
b