Dear Henry, Happy 12th Birthday Dear Henry, Happy 12th Birthday How you have grown!! Love, Alice
The "top" of the hierarchy of cards is the class Card.
Sometimes this is called the root of the hierarchy.
A variable of the root type, Card, can be used with any
of its descendants:
Card crd = new YouthBirthday( "Valerie", 7 ); crd.greeting(); // print a youth birthday greeting crd = new AdultBirthday( "Walter", 47 ); crd.greeting(); // print an adult birthday greeting crd = new Birthday( "Zoe", 30 ); crd.greeting(); // print a generic birthday greeting Holiday hol = new Holiday( "Kelly" ); Valentine val = new Valentine( "Jill", 42 ); crd = hol; crd.greeting(); // print a holiday greeting crd = val; crd.greeting(); // print a valentine greeting
When a program uses several related objects, it is often useful to have a reference variable than can be used with any of them.
(Thought Question: ) Say that you had a collection of 12 greeting card objects and wanted to keep them in an array. What type of array should you use?