image
image
image

Polymorphism

image

In Python, polymorphism refers to the ability to use a shared interface for several data types.

Start IDLE.

Navigate to the File menu and click New Window.

Type the following:

image

Discussion

The program above has defined two classes Tilapia and Shark all of which share the method jump() even though they have different functions. By creating common interface jumping_test() we allowed polymorphism in the program above. We then passed objects bonny and biggy in the jumping_test() function.

Practice Exercise

a.  In a doctor consultation room suggest the class and objects in a programming context.

b.  In a football team, suggest programming class and objects.

c.  In a grocery store, suggest programming class and objects.