Abstraction and Polymorphism

Home Up Search Java 2 API C++ Resources

Polymorphism and inheritance are really the same thing viewed from two different directions.  

  • Inheritance is how a subclass is everything that its superclass is.
  • Polymorphism is how a subclass can be substituted anywhere its superclass is being used.

Abstraction and polymorphism go hand-in-hand because the program may be running at an abstraction level that is higher than that needed to actually generate concrete, specific behavior.  In these situations, an abstract class is used by the calling class and the concrete subclasses inherit from it.   The calling class has a reference to the superclass, but since the subclass is an example of the superclass, the superclass reference can be set to it.   Likewise, any method of the superclass can be called and the subclass provides the actual concrete behavior is produced.