Card 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:

The class of the object.

Card Polymorphism

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.

QUESTION 6:

Could a variable Valentine val be used with a Holiday object?