Yes. See below.
Polymorphism means "having many forms."
In Java, it means that a single variable might be used with
several objects of related classes at different times in a program.
When the variable is used with "dot notation" variable.method()
to
invoke a method,
exactly which method is run depends on the object that the variable currently
refers to.
Here is an example:
. . . . // class definitions as before public class CardTester { public static void main ( String[] args ) { 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() } }
What will the program write?