title: java pick a random class/object
body: <p>Is there a way to pick a random object from an array of objects?</p>
  
  <p>I have tried a few ways that I could think of but none work.<br>
  I want to use a function in the random class (all classes will have the same function but different returns).</p>
  
  <p>I should have mentioned i am trying to return an image, and each time i try to return a random image it doesnt return anyting ("null")</p>
  
  <p>Here is some of my code I am having the problem with:</p>
  
  <pre><code>    Car car;
      Ford ford;
      Mazda mazda
      Fiat fiat
      Rover rover   
  
      Car carlist[] = {ford,fiat,mazda,rover}
  
  public void paint(){
  //this displays an image every 128 pixles 
          for (int i = 0;i&lt;Width;i+=128){
  
              for(int j=128; j&lt;Height;j+=128){
  // this draws the image (the image is declaired in each car's class as getImage)
                  g.drawImage((car.carList[rand.nextInt(5)]).getImage(), i, j , this);
                      }
                  }
  </code></pre>
  
  <p>The code works if i put an object in (instead of carcarList[rand.nextInt(5)])).
  Each of the cartypes extend Cars.</p>