There are two types of Binding shown in figure:
Static binding
Static binding is also known as Early binding. It can be resolved at compile time by compiler is know as static binding.
It all static, private and final method have also be bonded at compile time.
For Example:-
Create a class which name is StaticBinding.java
package com;
/**
*
* @author pradeep
*/
class StaticBinding{
}
class Binding extends StaticBinding{
public void RunBinding(){
System.out.println("Compile Static Binding");
}
public static void main( String args[]) {
Binding obj1 = new Binding();
obj1.RunBinding();
}
}
Result: Output of this program is
run:
Compile Static Binding
BUILD SUCCESSFUL (total time: 1 second)
Dynamic Binding :
Dynamic binding is also known as Late binding. It is resolved the problems at run time after static binding.
It is overriding both class as parent class and child class same methods. It is use for overridden method.
For Example:-
package in;
/**
*
* @author pradeep
*/
class StaticBinding{
public void RunBinding()
{
System.out.println("Compile Dynamic Binding");
}
}
class Binding extends StaticBinding{
public void RunBinding(){
System.out.println("Compile Static Binding");
}
public static void main( String args[]) {
StaticBinding obj2 = new Binding();
obj2.RunBinding();
}
}
Result: Output of this program is
run:
Compile Static Binding
BUILD SUCCESSFUL (total time: 2 seconds)
No comments:
Post a Comment