Polymorphism

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.

Answer:

No. Just one could have be used for each object in succession (assuming that the program does no more than is shown.) See below.

Polymorphism

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()

  }
}

QUESTION 13:

What will the program write?