Automatically selecting and creating class objects
- by Omin
Lets say that we have a box class:
class Box
{
private int width;
private int height;
//Box Constructor
public Box( int height )
{
this.height = height;
width = 450;
}
}
and a series of Box objects in our main:
Box Box1 = new Box(147);
Box Box2 = new Box(178);
Box Box3 = new Box(784);
Is there a way to use a "for" loop to go through these objects? Also, how would you make the computer create class objects for us?
eg. create 10 objects using:
for( int i=0; i>10; i++)
{
//method
}