View Single Post
  #2 (permalink)  
Old 11-05-2007, 10:45 PM
hardwired hardwired is online now
Senior Member
 
Join Date: Jul 2007
Posts: 1,266
hardwired is on a distinguished road
Code:
public class FlightInterface implements ActionListener { ... ArrayList<String> airlineArray = new ArrayList<String>(); ArrayList<String> flightNumArray = new ArrayList<String>(); ArrayList<String> originArray = new ArrayList<String>(); ArrayList<String> destinationArray = new ArrayList<String>(); ... // This next statement is using a constructor whose // method signature looks like this: //Flight(ArrayList<String> list1, ArrayList<String> list2, // ArrayList<String> list3, ArrayList<String> list4) // so the jvm looks for it in the Flight class. The only // constructor available has a method signature like this: //Flight(String s1, String s2, String s3, String s4) Flight Flight = new Flight(airlineArray, flightNumArray, originArray, destinationArray); class Flight { ... int totalFlights = 0; String airlineName; String flightNumber; String originCity; String destinationCity; public Flight(String airlineArray, String flightNumArray, String originArray, String destinationArray){ // The idea of passing arguments into a constructor is that // you can/will use these arguments to initialize or help // to initialize member variables. // The member variable airlineName is null/not_initialized. // So the next line will get a return value of null from // the method call. airlineName = getAirlineName(); flightNumber = getFlightNumber(); originCity = getOriginCity(); destinationCity = getDestinationCity(); totalFlights++; // To initialize the member variables (in class scope) with // the local variables (the agruments) you would start with //this.airlineName = airlineArray; // The argument "airlineArray" is declared as a String. // We would expect a String array to be declared as "String[]". }//
Reply With Quote