Java Reference
In-Depth Information
class, the definition of the method DiscountSale would not compile. If you omit
the definition of the method bill from the class DiscountSale , the output would
change to
floor mat Price and total cost = $10.0
floor mat Price = $11.0 Discount = 10.0%
Total cost = $11.0
Discounted item is not cheaper.
cup holder Price and total cost = $9.9
cup holder Price = $11.0 Discount = 10.0%
Total cost = $11.0
Items are not equal.
Note that all objects use the definition of bill given in the definition of Sale .
3. It would not be legal to add it to any class definition because the class Sale has no
method named getDiscount and so the invocation
theSale.getDiscount()
is not allowed. If the type of the parameter were changed from Sale to DiscountSale ,
it would then be legal.
4 . public boolean equals(Object otherObject)
{
if (otherObject == null )
return false ;
else if (getClass() != otherObject.getClass())
return false ;
else
{
DiscountSale otherDiscountSale =
(DiscountSale)otherObject;
return (super.equals(otherDiscountSale)
&& discount == otherDiscountSale.discount);
}
}
5. The definition of toString always depends on the object and not on any type
cast. So, the definition used is the same as without the added type cast; that is, the
definition of toString that is used is the one given in DiscountSale .
6. It would not be legal to add it to any class definition because the parameter is
of type Sale , and Sale has no method named getDiscount . If the parameter
type were changed to DiscountSale , it would then be legal to add it to any class
definition.
7 . ds was changed to map Price $ 5.0 discount 0.0%
Total cost $5.0
8 . ds was not changed.
Search WWH ::




Custom Search