Skip to content
Related Articles

Related Articles

Difference between Early and Late Binding in Java
  • Difficulty Level : Medium
  • Last Updated : 17 Jun, 2019

Early Binding: The binding which can be resolved at compile time by the compiler is known as static or early binding. Binding of all the static, private and final methods is done at compile-time.

Example:




public class NewClass {
    public static class superclass {
        static void print()
        {
            System.out.println("print in superclass.");
        }
    }
    public static class subclass extends superclass {
        static void print()
        {
            System.out.println("print in subclass.");
        }
    }
  
    public static void main(String[] args)
    {
        superclass A = new superclass();
        superclass B = new subclass();
        A.print();
        B.print();
    }
}
Output:
print in superclass.
print in superclass.

Late binding: In the late binding or dynamic binding, the compiler doesn’t decide the method to be called. Overriding is a perfect example of dynamic binding. In overriding both parent and child classes have the same method.

Example:






public class NewClass {
    public static class superclass {
        void print()
        {
            System.out.println("print in superclass.");
        }
    }
  
    public static class subclass extends superclass {
        @Override
        void print()
        {
            System.out.println("print in subclass.");
        }
    }
  
    public static void main(String[] args)
    {
        superclass A = new superclass();
        superclass B = new subclass();
        A.print();
        B.print();
    }
}
Output:
print in superclass.
print in subclass.

Difference table between early and late binding:

Early BindingLate Binding
It is a compile-time processIt is a run-time process
The method definition and method call are linked during the compile time.The method definition and method call are linked during the run time.
Actual object is not used for binding.Actual object is used for binding.
For example: Method overloadingFor example: Method overriding
Program execution is fasterProgram execution is slower

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :