Question

I understand how the implementation of dynamic binding works and also the difference between static and dynamic binding, I am just having trouble wrapping my brain around the definition of dynamic binding. Basically other than it is a run-time binding type.

Was it helpful?

Solution

Basically, dynamic binding means that the address for a function call is not hard-coded into the code segment of your program when it's translated into assembly language, and is instead obtained from elsewhere, i.e. stack variables, array lookups, etc.

At a higher level, if you have a line of code:

foo(bar) //Calls a funciton

If it can be known at compile time exactly what function this will call, this is static binding. If foo could mean multiple functions depending on things not knowable at compile time, this is dynamic binding.

OTHER TIPS

I understand it being evident in polymorphism. Typically when creating multiple classes that derive from a base class. If each one of the derived classes contains a function that each one uses. The base class can be used to execute a function of the derived classs and it will be properly call the correct function.

For example:

class Animal
{
void talk();
}

class Dog extends Animal
{
public void talk() { System.out.println("woof"); }
}

class Cat extends Animal
{
public void talk() { System.out.println("meow"); }
}

....
Animal zoo[2];
zoo[0] = new Dog();
zoo[1] = new Cat();

for(Animal animalToggle: zoo)
{
animalToggle.talk();
}

will print: woof meow

My interpretation hopefully it helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top