What is polymorphism?

Chaitali Patel
1 min readFeb 14, 2019

--

Polymorphism is ability of an Object to take many forms. Most common use of polymorphism in object oriented programming(OOP) occurs when parent class reference is used to refer to child class object.

Any Java object that can pass more than one IS-A test is considered to be polymorphic. In Java, all Java objects are polymorphic since any object will pass the IS-A test for their own type and for the class Object.

Dog IS-A Animal

Dog IS-A Pet

Dog IS-A Dog

Dog IS-A Object

Polymorphism allows an entity such as a variable, a function, or an object to have more than one form. A reference variable can refer to any object of its declared type or any subtype of its declared type. A reference variable can be declared as a class or interface type.

There are two types of polymorphism:

  1. Compile time polymorphism — method overloading
  2. Run time polymorphism — done using inheritance and interface(method overriding)

--

--