| 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 6 students
Calling Methods in an Enhanced For Loop
< Prev
Next >

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()

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
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
No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy