Well early and late binding is a good concept, well consider a situation where
you have a class with a method, now you call the method in your main method
using the object of the class, in this situation the complier knows which method
to call before execution, this is early binding..
eg
class Earlybinding{
void EarlyHello()
{
System.out.println("Hello Early binding...");
}
public static void main(String args[]){
Earlybinding ob = new Earlybinding();
ob.EarlyHello();
}
}
In late binding the complier doesn't know which method to call during complie
time, the method call is resolved only during runtime... this can be achived in
inheritance or by using an interface
eg
public interface LateBinding{
void meth1();
void meth2();
}
class LateBind implements LateBiding{
public static void main(String args[]){
// create a reference of the interface
// make sure to set the classpath appropriately
LateBinding ref;
// The following method invocation is resolved only during run-time this is an
example of
//late binding
ref.meth1();
ref.meth2();
}
}