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

Similar Programs Chapter Last Updated
Java Final Class Inheritance 02-08-2017
Java Final Method In Inheritance Inheritance 02-08-2017
Java Multilevel Hierarchical Inheritance Inheritance 01-08-2017
Java Super To Invoke Parent Class Method Inheritance 31-07-2017
Java Super To Invoke Parent Class Constructor Inheritance 30-07-2017
Java Overloaded Method To Print Array Inheritance 03-09-2016
Dynamic Method Dispatch In Java Example Inheritance 19-06-2016
Abstract Class In Java Example Inheritance 20-07-2016
Method Overriding In Java Example Inheritance 20-07-2016
Method Overloading In Java Example Inheritance 20-07-2016
Inheritance And Constructors In Java Inheritance 20-07-2016
Multilevel Inheritance In Java Example Inheritance 22-09-2018
Super() In Java Example Inheritance 14-07-2016
Inheritance In Java Example Inheritance 20-07-2016

1