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: 
Option 1: make `getCars()` a **static** method. e.g., in Car.java

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

```

Option 2: in Main.java, instantiate a new Car, then use it.

```
Car aCar = new Car();
Car[] arrayOfCars = aCar.getCars();

```

In your example, Option 1 feels like the right one, since the returned array appears to be independent of any particular car. However, if the method were "getSimilarCars()" and returned an array of cars that were similar to a particular instance of a Car, then option 2 would be preferred.
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();
    ...
}

```