0
private Trip[] trips;
private int[] distanceTraveled = new int[] { 8, 6, 15, 5 };

for (int i = 0; i < distanceTraveled.length; i++) {
  trips[i] = new Trip(0, i, distanceTraveled[i]);
}
for (Trip trip: trips) {
  System.out.println(trip.toString());
}

I am trying to write the values in distanceTraveled array to fill the array of objects for Trip[], but this code returns. Any help will be appreciated

@20ce73ec
@393679df
@56627197
Derek Wang
  • 10,098
  • 4
  • 18
  • 39
stronghold051
  • 332
  • 2
  • 12
  • Did you overwrite the `toString` method of `Trip`? – haoyu wang Oct 13 '20 at 03:03
  • The toString() method for Object gives you words like that. The default toString() just returns the hashCode() which might be thought of as the memory address of the object. You will need to override Trip#toString() if this is possible. – NomadMaker Oct 13 '20 at 04:12

1 Answers1

0

Override toString() method in Trip class.

Refer: https://www.geeksforgeeks.org/overriding-tostring-method-in-java/