Answer:

Here is one correct answer:

  public static void main ( String[] args )
  {
    Goods   toy ;
    Taxable tax = new Toy ( "Building Blocks", 1.49, 6 );

    toy = (Toy)tax;
    toy.display();
    System.out.println( "Tax: "+ ((Taxable)toy).calculateTax() );
  }

The first type cast must cast tax to a type Goods (or an ancestor). The second must cast toy to Taxable or to a class that implements Taxable.

Yet More Practice

Here is another possible answer:

  public static void main ( String[] args )
  {
    Goods   toy ;
    Taxable tax = new Toy ( "Building Blocks", 1.49, 6 );

    toy = (Goods)tax;
    toy.display();
    System.out.println( "Tax: "+ ((Toy)toy).calculateTax() );
  }

QUESTION 21:

Is this answer correct?