Question: Ok so I'm trying to get a better understanding of how to return a private variable from a class that I have created. I've only provided a small snippet of my main program to explain my question, so if more information is needed please let me know. My goal is to return a string from the class (working great), but also be able to return the private variables individually as needed (example used below is "flight\_number").

```
public class Flights {
    private String dest_city, dest_state, departureDate, departureTime;
    private int flight_number;

    public Flights(String city, String state, String dDate, String dTime, int flightNumber) {
        dest_city = city;
        dest_state = state;
        departureDate = dDate;  
        departureTime = dTime;
        flight_number = flightNumber;
    }

    public String toString() {
        return "Flight number: " + flight_number + " Destination: " + dest_city + "," + dest_state + "  Departing  on:" + departureDate + " at" + departureTime + ".";
    }
}

```

---

```
public class dummy {
    public static void main(String[] args) {
        // Uses the constructor to set values
        Flights flight1 = new Flights("Houston", "Texas", "12/20/2014", "12:40 pm", 100);
        System.out.println(flight1);
        System.out.println(flight_number); // Error: `flight_number` cannot be resolved to a variable.
    }
}

```

Answer: 
You need to add a `public` *getter* in `Flights` and call it from `main`:

```
public class Flights {
    // all the private fields
    public int getFlightNumber() {
        return this.flight_number;
    }
}

```

In `Main`:

```
public static void main(String[] args) {
    Flights flight1 = new Flights("Houston", "Texas"); //...
    System.out.println(flight1);
    System.out.println(flight1.getFlightNumber());  // call the getter
}

```
You should start with an editor like eclipse and that should help you get started quickly. Getters and Setters is what you need, but start with Eclipse and you should do better.