Question: I need to use an array of objects in my `main` class (lets call it `Main`). Now, I have a method in `Car`(a different class) that returns an initialised array of objects that I can use in `Main`.

How do I call the method in `Car` to return the array of objects, then assign my object array in `Main` to the returned array?

Like so...

*Main.java*

```
/* code */
Car cars[] = /* what goes here to get the initialised array from Car's method? */
/* Car cars[] = getCars(); doesn't work since I can't call getCars() as Main doesn't inherit from Car */

/* more code */

```

*Car.java*

```
public Car[] getCars()
{
  Car cars[] = new Car[NUM_OF_CARS];
  /* initialised all car elements */
  return cars;
}

```

Answer: 
Try making `getCars()` static, that way you can just call `Car.getCars()` from any context without having to initialize a distinct `Car` object.

For example:

```
public static Car[] getCars() {
   ...
}

```
There are two approaches to this:

* Make `Car` double as a "factory" of `Car` objects, changing `getCars` to `static`, or
* Recognize that `getCars` does not belong in `Car`, and should be moved to another class, say, `CarFactory`, instead.

Making a separate "factory" class is often a better choice:

```
public class CarFactory {
    public CarFactory() {
        // Do factory-specific initialization
    }
    public Car[] getCars() {
        ... // Make an array of Car objects
    }
}

```

Now in `Main` class you do this:

```
class Main {
    private static final CarFactory factory = new CarFactory();
    private final Car cars[] = factory.getCars();
    ...
}

```