previous | start | next

Polymorphic Types

  BankAccount a;

What type can be assigned to a?

Answer(s): BankAccount and SavingsAccount

E.g., both of these are allowed:

        a = new BankAccount(50000);         // right sides is the same type
or
        a = new SavingsAccount(3000, 2.75); // right side is a subtype

We say that BankAccount is a polymorphic type because at run
time it can hold references of different types (at different times).

   


previous | start | next