Limited access

Upgrade to access all content for this subject

Consider the following classes.

public class Truck
{
    private String make;
    private String model;
    private int price;

    public Truck(String mk, String md, int pr)
    {
        make = mk;
        model = md;
        price = pr;;
    }

    // other instance variables, constructors, and methods not shown

    public String toString()
    {
        return make + " " + model + " costs $" + price + ".";
    }
}
public class SmallTruck extends Truck
{
    public SmallTruck(String mk, String md, int pr)
    {
        super(mk, md, pr);
    }

    // other instance variables, constructors, and methods not shown
    // NO methods from the Object class were overridden in this class
}
public class Machine
{
    private String make;
    private String model;
    private int price;

    public Machine(String mk, String md, int pr)
    {
        make = mk;
        model = md;
        price = pr;;
    }

    // other instance variables and constructor not shown
    // NO methods from the Object class were overridden in this class
}

Consider the following code from the main method.

Truck ram = new Truck("Dodge", "Ram", 28000);
SmallTruck ranger = new SmallTruck("Ford", "Ranger", 20000);
Machine heater = new Machine("Economite", "Elite100", 3200);
System.out.println(ram);
System.out.println(ranger);
System.out.println(heater);

Which of the following would be reasonable output from this code?

A
Dodge Ram costs $28000.  
Ford Ranger costs $20000.  
Machine@42e816
B
Dodge Ram costs $28000.  
Ford Ranger costs $20000.  
Economite Elite100 costs $3200.
C
Dodge Ram costs $28000.  
SmallTruck@addbf1  
Machine@42e816
D
Truck@7yt348  
SmallTruck@addbf1  
Machine@42e816
E

No output prints, since the main is trying to print objects, not strings.

Select an assignment template