Binding is the connection of a method call to the method body. There are two types of binding: Static Binding or early binding and Dynamic Binding or late biding.
Before going into the discussion on Binding, we need to clarify what is Type:
1. Variable has one type, it can be either root or another (not the original).
Here, the data variable is an int type.
2. References have a style
3.Objects have one type. The object is an instance of a particular Java class, but it is also an instance of the superclass.
Here, d1 is a representation of the Dog class, but it is also an expression of Animal.
Example of Static Binding
Example of Dynamic Binding
In the above example, the object type can not be determined by the compiler, because the Dog expression is also an Animal expression. So the compiler does not know what kind of it, just know the base type.
To find out more about how to build constructor in java with detail example:
Before going into the discussion on Binding, we need to clarify what is Type:
1. Variable has one type, it can be either root or another (not the original).
Here, the data variable is an int type.
2. References have a style
3.Objects have one type. The object is an instance of a particular Java class, but it is also an instance of the superclass.
Here, d1 is a representation of the Dog class, but it is also an expression of Animal.
How static Binding in Java work
When the object type is decided at compile time (by the compiler), it is static binding. If there are any private, final or static methods in a class, it is static binding. Therefore, there can be no overloading of the results for object-oriented programming in static bindingExample of Static Binding
How dynamic Binding in Java work
When the object type is decided at runtime, it is dynamic binding.Example of Dynamic Binding
In the above example, the object type can not be determined by the compiler, because the Dog expression is also an Animal expression. So the compiler does not know what kind of it, just know the base type.
To find out more about how to build constructor in java with detail example:
Comments
Post a Comment