Yes. See below.
Polymorphism means "having many forms." In Java, it means that one variable might be used with several objects of related classes at different times in a program.
Say that a variable is used with dot notation: variable.method()
.
The method that is run belongs to 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?