Dynamic Binding
Contents
In a very simple sense, when a piece of code is compiled, the compiler sets up all the information that it knows. For example, the types of the methods and variables. These are statically bound.
However, when you have a given class that extends another class, the compiler doesn't store the parent class in the class file for the child class. Instead, when the code actually runs, the parent class information is loaded, and then the child class information is superimposed on top.
This is what is meant by dynamic binding - where information is only set when needed.
On a more technical level:
Static | Dynamic |
---|---|
Occurs during compile time | Occurs during runtime |
Used by private , final and static methods and variables | Used by virtual (redefinable) methods |
Use class information | Use the object |
Bonds overloaded methods | Bonds overriden |
- Information from here