Polymorphism Exercises

  < Previous  Next >
  1. Discuss with someone else:
    1. The benefits of using polymorphism
    2. Three scenarios that could benefit from polymorphism
  2. Write a simple Java program that has a polymorphic call. Use comments to label each of the essential ingredients for a polymorphic call.
  3. In the AccountsDriver class from the Inheritance Exercises, add a (static) method named displayAccount() that takes a SimpleBankAccount reference. In that method, make a call to toString() on that reference parameter and display the results. Furthermore, in the main() method (in that same class, replace):
    System.out.print( checking.toString() );
    with
    displayAccount( checking );
    and
    System.out.print( savings.toString() );
    with
    displayAccount( savings );