Goods[]
Goods
ObjectsHere is a modified testing program that uses an array:
public class Store { public static void main ( String[] args ) { Goods[] inventory = new Goods[10]; inventory[0] = new Goods( "bubble bath", 1.40 ); inventory[1] = new Food ( "ox tails", 4.45, 1500 ); inventory[2] = new Book ( "Emma", 24.95, "Austin" ); inventory[3] = new Toy ( "Leggos", 54.45, 8 ); inventory[0].display(); inventory[1].display(); inventory[2].display(); inventory[3].display(); } }
Since each child class is-a Goods
,
an array of type Goods[]
can be used with any of them.
The array inventory
has 10 slots,
but the program uses only 4 of them, like this:
As always,
each slot of the array is a reference variable
which can refer to an object that has
been created with a new
.
Is each of the classes Toy
and Book
taxable?