Static And Dynamic Binding In Java
Chapter:
Inheritance
Last Updated:
24-03-2017 03:37:51 UTC
Program:
/* ............... START ............... */
public class Vehicle {
public void showSpeed() {
System.out.println("Vehicle class speed.");
}
}
public class Car extends Vehicle {
public void showSpeed() {
System.out.println("Vehicle class speed.");
}
public void start() {
System.out.println("Car started");
}
public static void main(String[] args) {
Car c1 = new Car();
c1.start(); // static or early binding
Vehicle c2 = new Car();
c2.showSpeed(); // dynamic or late binding
}
}
/* ............... END ............... */
Notes:
-
Static and dynamic binding are important concepts in java. Static binding is also called as early binding and dynamic binding as late binding.
- Binding means connecting method call to method body in class. In binding compiler binds data with method.
- Compiler resolves the binding at the compile time only then such a binding is called Static Binding or Early Binding.
- Compiler cannot resolves the binding at the compile time but at runtime then such a binding is called Dynamic Binding or Late Binding.
Tags
Static and Dynamic binding, Java