Automatically selecting and creating class objects

Posted by Omin on Stack Overflow See other posts from Stack Overflow or by Omin
Published on 2012-11-19T15:48:07Z Indexed on 2012/11/19 17:00 UTC
Read the original article Hit count: 172

Filed under:
|
|

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
}

© Stack Overflow or respective owner

Related posts about java

Related posts about oop