Understand the concepts of classes, objects, and polymorphism with the help of an interactive example in this lesson.

In the next example, we will look at another object-oriented programming concept, Polymorphism.

Polymorphism in Java

To explain Polymorphism in a few sentences, we can think of a computer mouse. Consider the ‘double click’ feature. It would be a state-changing method, of course, if you wanted to write a mouse class and create an object.

When we double click a Word Document, it opens up the text editor. When we double click on an executable file, the program starts running. Similar objects often receive the same message but perform different acts. That is Polymorphism in a nutshell.

Coding example: 87

The following example will show you how this concept of Polymorphism is applied in our superclass and subclass.

Get hands-on with 1200+ tech skills courses.