hope following example helps you .........
class A
{
public void foo()
{
System.out.println("Class A");
}
}
class B extends A
{
public void foo()
{
System.out.println("Class B");
}
}
public class C
{
public static void main(String [] args)
{
A a=new A();
B b=new B();
A ref=null;
a.foo(); // early binding --- calls method foo() of class A ....
decided at compile time
b.foo(); // early binding --- calls method foo() of class B ....
decided at compile time
ref=b;
ref.foo(); // late binding --- --- calls method foo() of class B
.... decided at Run time
}
}