The Java Program: DDD.java

  1 // DDD.java -- double dynamic dispatch
  2 
  3 class Base {
  4    void method1 () {
  5       System.out.println ("Base.method1()");
  6       method2();   // Method to invoke is chosen dynamically
  7    }
  8    void method2 () { System.out.println ("Base.method2()"); }
  9 }
 10 
 11 class Derived extends Base {
 12    void method1 () {
 13       System.out.println ("Derived.method1()");
 14       super.method1();
 15    }
 16    void method2 () { System.out.println ("Dervied.method2()"); }
 17 }
 18 
 19 public class DDD {
 20    public static void main (String[] args) {
 21       new Derived().method1();
 22       new Base().method1();
 23    }
 24 }