The class of the object.
It makes sense that the object's method is invoked, since, after all, the method is part of the object and the method uses the object's data. Here is an example from the previous chapter:
. . . . // class definitions as before public class CardTester { public static void main ( String[] args ) throws IOException { Card card = new Holiday( "Amy" ); card.greeting(); //Invoke a Holiday greeting() card = new Valentine( "Bob", 3 ); card.greeting(); //Invoke a Valentine greeting() card = new Birthday( "Cindy", 17 ); card.greeting(); //Invoke a Birthday greeting() } }
The reference variable card
is used three times,
each time with a different class of object.
Since Card
is a parent to the three different classes,
the variable card
can be used for each.
Could a variable Valentine val
be used
with a Holiday
object?