At the vary basic, binding is assigning one thing to another, usually, values to variables either by explicit declaration or implicit declaration.
For the newbies in programming, the terms, explicit and implicit declaration seems daunting its really not. Explicit declaration simply implies a statement that defines the variable name and it's type e.g
public int i;
while in implicit, the default convention is implemented e.g
int i;
it assumes it is public.
Binding int a, b = 0;
can occur at run-time or at compilation time, when it happens at run-time, the current state of the variable is changed in that a value is assigned to it. For instance
int a, b = 0, c;
for(a = 0; a < 10; a++){
b+=c;
}
the state of c
changes as values are been added as the for
loop is being executed.
Types of Binding
Dynamic Binding : Variable are bound to a type depending on the value assigned.
this happens at run-time.
Static Binding : This happens at compile time where the compiler figures out what variable to assign to what method or function. A perfect example is method overloading where two methods have same name but different number or type of parameter. If two parameters are passed in a method A
(that has two parameters), the compiler figures out that the method to return is A
.
Hope this helps.
Top comments (1)
I read this three times and cannot understand it.
Binding int a, b = 0;
what exactly is going on in this line?