Food have?
toString()Toy have?
toString() and calculateTax()
Recall that all child classes have a toString()
method which they inherit from the
class Object
unless the child class overrides it (as is done here.)
Here is a class definition for Goods.
The two instance variables are made protected so that children classes
can use them.
public class Goods
{
protected String description;
protected double price;
public Goods( String des, double pr )
{
description = des;
price = pr;
}
public String toString()
{
return "item: " + description + " price: " + price + " ";
}
}
Here is a skeleton of the class Food,
a child of Goods.
It adds the variable calories.
Fill in the blanks. Click here for a