Wednesday, 14 March 2018

Static Binding and Dynamic Binding In Java



What Exactly Binding Is : -
Binding generally refers to a mapping of one thing to another, or in other words we can say connecting a method call to the method body is known as binding.

It can be clear with following diagram


In the above diagram “a1.methodTwo” called is binding corresponding methodTwo definition and “a1.methodOne” called is binding corresponding methodOne definition.

For every method call there should be proper method definition.

Different type of Binding:-
  1. static binding (also known as early binding).
  2. dynamic binding (also known as late binding).
1) Static Binding: - When type of object is determine at compile time (by the compiler), it is known as static binding. It is also called as early binding.



2. Dynamic Binding: - When type of object is determine at run time, it’s is known as Dynamic Binding. It is also called as late binding.



Few Important difference between static and dynamic binding :-

1.      Static binding in Java occurs during compile time while dynamic binding occurs during runtime.
2.      privatefinal and static methods and variables use static binding and are bonded by compiler while virtual methods are bonded during runtime based upon runtime object.
3.      Static binding uses Type (a class in Java) information for binding while dynamic binding uses object to resolve binding.
4.      Overloaded methods are bonded using static binding while overridden methods are bonded using dynamic binding at runtime.


















1 comment:

  1. I usually struggle with the code when it come to design the good framework or class .. I mast say this article will help to build a good cording standard. Thanks for posting this

    ReplyDelete