go to previous page   go to home page   go to next page

Answer:

((Book)item1).getAuthor()

Because you want to:


When is a Type Cast Needed?

Now examine the following:

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

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

QUESTION 22:

Is a type cast necessary? Where should it go?


go to previous page   go to home page   go to next page