Why are the red parentheses needed in:

    ((Book)item1).display();

A good answer might be:

Because you want to:

  • First, cast item1 to type Book.
  • Then, invoke the display() method that objects of type Book have.

When is a Type Cast Needed?

Now examine the following:

  public static void main ( String[] args )
  {
    Book    book ;
    Taxable tax = new Book ( "Emma", 24.95, "Austin" );

    book = tax;
    book.display();
    System.out.println( "Tax on item 1 "+ book.calculateTax() );
  }

QUESTION 17:

Is a type cast necessary? Where should it go?

Click Here after you have answered the question