?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Difficult

Calculating Cost of House (House Class)

APCSA-NEN1KM

Given the following classes:

public class House 
{
    // instance variables, constructor, other methods not shown

    // Calculates cost of the house using the square footage
    public double calcCost() 
    {
        // Implementation not shown
    }
}

public class HouseWithGarage extends House 
{
    private double garageCost; // Cost of the garage

    // instance variables, constructor, and methods not shown
}

The cost of the house with the garage is the cost of the house plus the cost of the garage.

How would you redefine the calcCost() method in the HouseWithGarage class?

A
public double calcCost() 
{
    return super.calcCost() + garageCost;
}
B
public double calcCost() 
{
    return calcCost() + garageCost;
}
C
public double calcCost() 
{
    double houseCost = calcCost();
    double totalCost =houseCost + garageCost;
    return totalCost;
}
D
public double calcCost() 
{
    return super.calcCost();
}
E
public double calcCost() 
{
    double totalCost = super.calcCost() + garageCost;
}