Limited access

Upgrade to access all content for this subject

Assume that Truck extends Vehicle and Car extends Vehicle. SmallTruck extends Truck and LargeTruck extends Truck. Assume that there are valid constructor methods in each class and getMake() and getModel() are methods defined in each of these classes.

Consider the following method defined in a client class.

public static void printTruckMakeAndModel(Truck t)
{
     SmallTruck truck = (SmallTruck) t;
     System.out.println(truck.getMake()+" "+truck.getModel());
}

Which of the following method calls (from the main method in the client class) would throw a ClassCastException?

I.

printTruckMakeAndModel(new Truck("Dodge", "Ram", 120000, 40000));

II.

printTruckMakeAndModel(new SmallTruck("Ford", "Ranger", 50000, 1000));

III.

printTruckMakeAndModel(new LargeTruck("Ford", "F110", 11000, 600));
A

I only.

B

II only.

C

III only.

D

I and III only.

E

I, II, and III.

Select an assignment template