Search This Blog

Sunday, January 31, 2010

polymorphism in java

let,s talk something about polymorphism. all of we know that generally "poly" means "many".
so polymorphism means "there is only one thing and it has many forms".

Lets understand it from a simple example:
Suppose there is a company. In that company there will be many departments .
In each department there will be a manager ie;account department will have Account manager,Hr department will have HR manager etc etc...

Now suppose the Boss of the company wants to arrange a meeting for all the managers,
then he will simply say that call all the managers then managers of all departments will come for meeting.
there is no need to call everyone individually.every manager will come in the meeting.

The main Use of Polymorphism is "Reduce the complexity"

There are two types of polymorphism.
1. Compile time Polymorphism
2.RunTime Polymorphism

Compiletime Polymorphism:
In compile time polymorphism object is bounded with its functions
at compile time.
Now there arises a question that object is created at run time not at compile time.
So here it is assumed that when the object will create at run time then which functions will run.
Run Time Polymorphism:
In this, object is bounded with its functions at run time.

Compiletime Polymorphism is achieved by two ways.

first one operator Overloading
second is function Overloading

java does not support Operator Overloading.

Runtime Polymorphism is achieved by Function Overriding

Futher we will talk later.

Khemraj Singh
Sun Certified Java Programmer

No comments:

Post a Comment