// Dispatch.java -- illustrates OO dynamic dispatch of methods

class Base {
    void method() {
        System.out.println ("Base's method");
    }
}

class Derived extends Base {
    @Override
    void method() {
        System.out.println ("Derived's method");
    }
}

class Dispatch {
   public static void main (String args[]) {

      Base a = new Derived();

      /*
        The method actually invoked in the call below does
        not depend on the static type ("Base" in this case)
        of the variable ("a") known by the compiler, but
        on the value of the object at runtime, in this case
        an instance of class "Derived".
      */

      a.method();     // Derived's method called

    }
}