Static polymorphism

Static polymorphism

The polymorphism exhibited at compilation time is called static polymorphism. Here the java compiler knows without any ambiguity which method is called at the time of compilation. JVM executes the method later, but the compiler knows and can bind the method call with method code at the time of compilation.

Program
class sample
{
public int add(int x, int y)
{
return x+y;
}
public int add(int x, int y, int z)
{
return x+y+z;
}
}
class test
{
public static void main(String[] args)
{
sample s=new sample();
System.out.println(s.add(10,20)); System.out.println(s.add(10,20,30));
}
}

Output:
30
60

Leave a Reply

Your email address will not be published. Required fields are marked *