go to previous page   go to home page   go to next page

Answer:

Yes. See below.


Polymorphism

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

  }
}

QUESTION 16:

What will the program write?


go to previous page   go to home page   go to next page