Polymorphism in Java

What is Polymorphism?

--Polymorphism in Java is a concept by which we can perform a single action in different ways.
--Polymorphism is derived from 2 Greek words: poly and morphs. The word "poly" means many and "morphs" means forms. So polymorphism means many forms.
--There are two types of polymorphism in Java: compile-time polymorphism and runtime polymorphism.
--Polymorphism can be achieved by method overloading and method overriding

Method Overloading:

--Method Overloading is a feature that allows a class to have more than one method having the same name, if their argument lists are different.
--Signature should be different:

      1. Number of parameters.
      2. Data type of parameters.
      3. Sequence of Data type of parameters.

Method Overriding:

--Declaring a method in sub class which is already present in parent class is known as method overriding.
--Advantage: The main advantage of method overriding is that the class can give its own specific implementation to a inherited method without even modifying the parent class code.

Types of Polymorphism:

1. Static Polymorphism (Static Binding - Early binding) is also known as compile time binding or compile time polymorphism-- Method Overloading in an example -- when type of object is determined at compiled time it is known as Static binding.
2. Dynamic Polymorphism (Dynamic Binding -late binding) is also known as runtime time binding or run time polymorphism -- example method overriding-- When type of object is determined at run time, it is known as dynamic binding.

To get more details please watch below youtube video and Subscribe the channel.




No comments:

Post a Comment