Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 5: Writing Classes
Start Practice TestPractice Test
About Exam
easy Solved by 4 students

Calling Methods in an Enhanced For Loop

Mark
< Prev
Next >

Consider the following Vehicle interface and Fleet 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 expressions can replace /* expression */ so that the getTotalMileage method correctly calculates and returns the total mileage for all vehicles in the fleet?

A

myVehicles.get(v).getMileage()

B

myVehicles[v].getMileage()

C

v.getMileage()

D

getMileage(v)

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Total Time
Score
#1kaisuki11 0m 00s 100
#2bommasam00014 1m 19s -9
#3gtsak3111 2m 46s -66
#4y.seong202712 5m 05s -215
Items per page:
10
1 – 4 of 4

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|