title: Java Inheritance - Getting a Parameter from Parent Class
body: <p>I'm trying to take one parameter from the parent class of Car and add it to my array (<code>carsParked</code>), how can i do this?</p>
  
  <p>Parent Class</p>
  
  <pre><code>public class Car
  {
      protected String regNo;       //Car registration number
      protected String owner;       //Name of the owner
      protected String carColor;
  
      /** Creates a Car object
       * @param rNo - registration number
       * @param own - name of the owner
       **/
      public Car (String rNo, String own, String carColour)
      {
          regNo = rNo;
          owner = own;
          carColor = carColour;
      }
  
      /** @return The car registration number
       **/
      public String getRegNo()
      {
          return regNo;
      }
  
      /** @return A String representation of the car details
       **/
      public String getAsString()
      {
          return "Car: " + regNo  + "\nColor: " + carColor;
  
      }
      public String getColor()
      {
          return carColor;
      }
  }
  </code></pre>
  
  <p>Child Class</p>
  
  <pre><code>public class Carpark extends Car
  {
      private String location;        // Location of the Car Park  
      private int capacity;           // Capacity of the Car Park - how many cars it can hold 
      private int carsIn;             // Number of cars currently in the Car Park   
      private String[] carsParked;
  
      /** Constructor for Carparks
       * @param loc - the Location of the Carpark
       * @param cap - the Capacity of the Carpark
       */
      public Carpark (String locations, int room)
      {
  
          location = locations;
          capacity = room;
      }
      /** Records entry of a car into the car park */
      public void driveIn()
      {
           carsIn = carsIn + 1;
  
  
  
      }
  
      /** Records the departure of a car from the car park */
      public void driveOut()
      {
          carsIn = carsIn - 1;
      }
  
      /** Returns a String representation of information about the carpark */
      public String getAsString()
      {
          return location + "\nCapacity: " + capacity +
               "  Currently parked:  " + carsIn + 
               "\n*************************\n";
      }
  
  }
  </code></pre>
  
  <p>Last Question Method</p>
  
  <blockquote>
    <p>public String getCarsByColor (String carColour)</p>
    
    <p>{</p>
  
  <pre><code>  for (int num = 0; num &lt; carsParked.length; num++)
      {
          if ( carColour.equals(carsParked[num]) )
          {
              System.out.print (carsParked[num]);
  </code></pre>
  </blockquote>
  
  <pre><code>        }
      }
  return carColour;
  
  }
  </code></pre>
  
  <p>I have this so far so that if "red" is put in the parameters, it would list all the cars with the color red and it's corresponding information but does not seem to work ~_~.</p>