Difference between Static and Dynamic Binding

Key Difference: Static binding happens when the code is compiled, while dynamic bind happens when the code is executed at run time.

The term binding, static and dynamic, are basic concepts in java programming. These concepts are taught early on during learning java and are popular questions that are asked during job interviews. The reason for this is because these simple concepts often let the interviewers know how well versed one is with java programming.

Before we begin with the difference between static and dynamic binding, let’s first understand what exactly binding is. Binding refers to the link that is created between method call and method definition. It lets the system know which code should be executed in what manner. If any method call does not have a method definition, it results in the system showing an error. Static and dynamic binding determines when the code is actually executed.

While most references are resolved during compile time, there are some references that require an actual object and are resolved at run time. This is major difference between static and dynamic. Static binding happens when the code is compiled, while dynamic bind happens when the code is executed at run time.

During compilation, while binding, the compiler does not check the type of object to which a particular reference variable is pointing, it just checks if each method has a definition. This is known as static or early binding. Overloaded methods are bonded using static binding.

In dynamic or late binding, while binding, the complier checks for an actual object to bind and hence requires the program to run. Overridden methods are bonded using dynamic binding.

Comparison between Static and Dynamic Binding:

 

Static Binding

Dynamic Binding

Time of binding

Happens at compile time

Happens at run time

Actual object

Actual object is not used for binding

Actual object is used for binding

Also known as

It is also known as early binding because binding happens during compilation

It is also known as late binding because binding happens at run time

Example

Method overloading

Method overriding

Methods of binding

Private, static and final methods show static binding. Because, they cannot be overridden.

Other than private, static and final methods show dynamic binding. Because, they can be overridden.

Class

Type class

Object class

Image Courtesy: javatpoint.com, thecrazyprogrammer.com

Most Searched in Sports Most Searched Non-Alcoholic Drinks
Most Searched in Education and References Most Searched in Environment
Cigarettes vs Cigar
Synchronous Motor vs Induction Motor
iOS 8 vs iOS 9
Point vs Line vs Plane

Comments

This gives some inner sights on the static and dynamic binding concepts Thanks.

Add new comment

Plain text

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.