Tuesday, December 13, 2011

What is Static Ploymorphism in java?

Static Ploymorphism: Ability to take more than one form is called polymorphism. if the polymorphism exhibits at compile time, then it is called  static polymorphism. Method overloading is an example of static polymorphism. 

Example: 

class sumvalue
{
int s;
void sum(int x,int y)
{
s=x+y; 
System.out.println("sum of two integers is:"+s)
}
void sum(int x,int y,int z)
{
s=x+y+z;
System.out.println("sum of three integers is:"+s);
}
}

class staticpolymorphism
{
public static void main(String args[])
{
sumvalue v=new sumvalue();
v.sum(2,3);
v.sum(2,3,4);
}
}

Output:
sum of two integers is:5
sum of three integers is:9