1

Is there any direct relationship between Late Binding and Overriding, similarly for Early Binding and Overloading?

They (Binding/Overriding/Overloading) can be termed as ways to implement polymorphism, but is there any "Direct Relationship" ex: Late Binding is a sub/super concept to Overriding and vice versa etc?

cspolton
  • 4,495
  • 4
  • 26
  • 34
Ashish Jain
  • 4,667
  • 6
  • 30
  • 35

1 Answers1

1

They are orthogonal (independent) concepts.

  • Overloading, Overriding: Forms of polymorphism
  • Early binding/Late binding: In the former, the method to call is known at compile time. In the latter, at runtime.

Of course, an implementation of overriding usually implies using late binding, because you will only know the object's real type at runtime. But that's just a special case.

dario_ramos
  • 7,118
  • 9
  • 61
  • 108
  • So can it be termed Overriding is based on Late Binding and overloading on Early binding - "ALWAYS"? – Ashish Jain Oct 17 '12 at 12:45
  • That's the typical scenario, but it can be different. Suppose you have a base class `Pet`, and derived classes `Dog` and `Cat`, and a virtual method `Speak` overriden in both derived classes. If a compiler/interpreter sees the following statements: `Pet p = new Dog(); p.Speak();`, it has enough information to perform early binding (it knows that p will always be a `Dog`). – dario_ramos Oct 17 '12 at 12:50
  • Good!! Got the meaning of usually now :) Thanks. – Ashish Jain Oct 17 '12 at 12:53