Limited access

Upgrade to access all content for this subject

Consider the following method.

// Assume that Truck is a valid class with a working calcMPG() method
public static double getMPG(String owner, Truck t, int[] gallons)
     if (owner.length()>0)
          return 0;

     int totalGallons = 0;
     for (int i=0; i<gallons.length; i++)
         totalGallons += gallons[i];

     return t.calcMPG(totalGallons);

In which of the following situations would this method always throw a NullPointerException?


When owner points to null and t points to a valid Truck and gallons is a full array of ints.


When t points to null and owner is a valid owner name and gallons has at least one element.


When gallons points to null and owner points to "Smith" and t points to a Truck object.


When both t and gallons point to null.


When either t or gallons points to null.

Select an assignment template