The foundational principle of polymorphic behavior

 

  • Polymorphic behavior relies on these facts:

    1. An instance of a subclass is also an instance of its superclass:

      • A Circle is an GeometricObject
      • An GeometricObject is an Object
      • A Circle is an Object

    2. Subclasses can define a different behavior than its superclass

The foundational principle of polymorphic behavior

 

  • The polymorphic behavior of selectionSort( ) is a result of these mechanisms:

    1. selectionSort(GeometricObject) can also so any of its subclasses because an instance of it subclass (Circle or Rectangle) is also an instance of GeometricObject:

    2. Subclasses (Circle and Rectangle) can define a different getArea( ) than its superclass --- and will cause selectionSort( ) to use a different (more suitable) getArea( ) in sorting !