Compile time polymorphism

Compile time polymorphism

  •  In compile time polymorphism method declaration is binded to method
    implementation at the time of compilation by compiler.
  • This type of binding is known as static binding or early binding.
  • The compile time binding happen for static method,final method and overload method.
  • The binding done at compile time can not be re-binded.
  • Example of compiletime polymorphism
    ~ Method overloading
    ~ Constructor overloading
    ~ Static method and final method
Example of Compile time polymorphism

class Demo12
{

  void test()

   {

     System.out.println("running no arg test method");
   }

  void test(int arg)
   {

     System.out.println("running int arg test method");

   }
    static void test(double arg1)//static method
     {

       System.out.println("running double arg static test method");
     }

}

public class CompiletimePolymorphysm
  {
      public static void main(String[] args) {

            System.out.println("*************************");

            Demo12 obj1=new Demo12();

            obj1.test();//calling no arg test method

            obj1.test(10);// calling int arg test method

            System.out.println("*************************");

            Demo12.test(12.4);//calling static test double arg method

            System.out.println("**************************");

   }
}

output:

*************************
running double arg static test method
**************************

Leave a Reply