Skip to main content

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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
**************************