Muhammad Imran Ansari
What is Static Binding and Dynamic Binding? Which is preferred? Why?

What is Static Binding and Dynamic Binding? Which is preferred? Why?

By Muhammad Imran Ansari in OOP/OOD on Jan 18 2023
  • Tuhin Paul
    Apr, 2023 15

    Static binding (also known as early binding) is when the method call is resolved at compile-time based on the type of the reference variable, using the static type of the object. In other words, the method to be called is determined based on the declared type of the object, and this decision is made at the time of compilation. Static binding is typically used with methods that are private, final, or static.

    Dynamic binding (also known as late binding) is when the method call is resolved at runtime based on the type of the object itself, using the actual type of the object. In other words, the method to be called is determined based on the actual type of the object at runtime, and this decision is made dynamically. Dynamic binding is typically used with virtual or overridden methods that are designed to be polymorphic.

    Dynamic binding is generally preferred over static binding because it provides more flexibility and extensibility in the code. With dynamic binding, the behavior of a program can be changed at runtime by substituting different objects that have different implementations of the same method. This allows for more modular and reusable code, and it also enables a wider range of design patterns and architectural styles.

    • 1
  • Aravind  Govindaraj
    Jan, 2023 23

    Example of static binding means early binding, when you drag and drop button. you can see the code which event to be called. this has determined before runtime.
    If you want to implement dynamic biding, it means this has been decied on runtime, for eg., you may have two types such as premium customer and normal customer of events this may be invoked based on which customer logged in the system.

    use cases are differ based on the scenario which you would like to impelment.

    • 1
  • Rajeev Kumar
    Jun, 2023 29

    static binding work in compile time and Dynamic Binding work in Runtime.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS