Calling Methods in an Enhanced For Loop
Which of the following can be used to replace /* expression */ so that getTotalMileage returns the total of the miles traveled for all vehicles in the fleet?
Consider the following interface and class declarations.
public interface Vehicle
{
/** @return the mileage traveled by this Vehicle */
double getMileage();
}
public class Fleet
{
private ArrayList<Vehicle> myVehicles;
/** @return the mileage traveled by all vehicles in this Fleet */
public double getTotalMileage()
{
double sum = 0.0;
for (Vehicle v : myVehicles)
{
sum += /* expression */ ;
}
return sum;
}
// There may be instance variables, constructors, and methods that are not shown.
}
Which of the following can be used to replace /* expression */ so that getTotalMileage returns the total of the miles traveled for all vehicles in the fleet?
A
myVehicles[v].getMileage()
B
v.getMileage()
C
getMileage(v)
D
myVehicles.get(v).getMileage()
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | kaisuki | 1 | 1 | 0m 00s | 100 |
| #2 | bommasam000 | 1 | 4 | 1m 19s | -9 |
| #3 | gtsak31 | 1 | 1 | 2m 46s | -66 |
| #4 | y.seong2027 | 1 | 2 | 5m 05s | -215 |
Items per page:
10
1 – 4 of 4
APFIVE