0% found this document useful (0 votes)
6 views1 page

Document1

Polymorphism is a core concept of object-oriented programming (OOP) that allows objects of different types to be accessed through the same interface, with each type providing its own implementation. Java supports two types of polymorphism: static (compile-time) and dynamic, with static polymorphism achieved through method overloading based on differing parameters. This enables developers to create logical code by using the same method name for similar functionalities within a class.

Uploaded by

caglar.toky
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Document1

Polymorphism is a core concept of object-oriented programming (OOP) that allows objects of different types to be accessed through the same interface, with each type providing its own implementation. Java supports two types of polymorphism: static (compile-time) and dynamic, with static polymorphism achieved through method overloading based on differing parameters. This enables developers to create logical code by using the same method name for similar functionalities within a class.

Uploaded by

caglar.toky
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Object-Oriented Programming has different concepts allowing developers to build

logical code. One of these concepts is polymorphism. But what is polymorphism?

Polymorphism is one of the core concepts of object-oriented programming (OOP) that


describes situations in which something occurs in several different forms. In
computer science, polymorphism describes the concept that you can access objects of
different types through the same interface. Each type can provide its own
independent implementation of this interface.

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.

Different Types of Polymorphism


Java supports 2 types of polymorphism:

-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..

You might also like