Java Static And Dynamic Binding
Static Binding
- Type of the object is determined at compiled time by the compiler.
- Any private, final or static method in a class is example of static binding.
Sample Code
Public class Superman{
private void fly(){
System.out.println("Superman is flying!");
}
public static void main(String args[]){
Superman sm=new Superman();
sm.fly();
}
}
public static void main(String args[]){
Superman sm=new Superman();
sm.fly();
}
}
Dynamic Binding
- Type of the object is determined at run-time.
Sample Code
class World{
void travel(){
System.out.println("I am travelling the World..");
}
}
class Island extends World{
}
class Island extends World{
void travel(){
System.out.println("I am travelling the island..");
}
public static void main(String args[]){
public static void main(String args[]){
World w=new Island();
w.travel();
}
}
w.travel();
}
}
Comments
Post a Comment