Late binding early binding java

Late binding early binding java

OR
What is late binding and early binding in java

Answer :

Late binding Early binding
Late binding applies at runtime Early binding applies at compile time
Object type are unknown until runtime and its value will be assigned dynamically Variable type are known and check at compile time i.e. when you define variable static
Method dynamic dispatch is an example of late binding through which we achieve polymorphism Static blocks are example of early binding
Method overriding is an example of late binding Method overloading is an example of early binding

Please see example below:

package com.javahonk.earlylatebinding;

import java.util.HashMap;
import java.util.Map;

public class EarlyLateBinding {

	// Early binding
	private static final Map<String, String> MAP = 
			new HashMap<String, String>();
	// Early binding
	static {
		MAP.put("First Name: ", "Java");
		MAP.put("Last Name: ", "Honk");
	}

	public static void main(String[] args) {
		A a = new B();

		if (a instanceof B) {
			System.out.println("Late binding");
		}

	}

}

class B extends A {

}

class A {

}

 

Output:


Late binding early binding java

Leave a Reply

Your email address will not be published. Required fields are marked *