Document1
Document1
You can perform a simple test to know whether an object is polymorphic. If the
object successfully passes multiple is-aor instanceof tests, it’s polymorphic. As
described in our post about inheritance, all Java classes extend the class Object.
Due to this, all objects in Java are polymorphic because they pass at least two
instanceofchecks.
-static or compile-time
-dynamic
Static Polymorphism
Like many other OOP languages, Java allows you to implement multiple methods within
the same class that use the same name. But Java uses a different set of parameters
called method overloading and represents a static form of polymorphism.
The parameter sets have to differ in at least one of the following three criteria:
-They need to have a different number of parameters, one method accepting 2 and
another one accepting 3 parameters
-The types of parameters need to be different, with one method accepting a String
and another one accepting a Long
-They need to expect the parameters in a different order. For example, one method
accepts a String and a Long, and another one accepts a Long and a String. This kind
of overloading is not advisable because it makes the API difficult to understand
In most cases, these overloaded methods provide a different but very similar
functionality.
Like many other OOP languages, Java allows you to implement multiple methods within
the same class that use the same name..