// This code demontrates the dynamic binding principle
// The compiler does not know in advance whose method toString() to call
// The decision is made during the runtime.

public class HelloHi
{
  public static void main(String[] args)
  {
    Hello h = null;

    int choice = Integer.parseInt(args[0]);  // get a number (0 or 1)

    if (choice == 0)
      h = new Hello();                       // initialize h with either
    else                                     // a superclass instance or
      h = new Hi();                          // the subclass one

    System.out.println(h);                   // what will be output?
  }
}

class Hello                                  // a superclass
{
  public String toString()
  {
    return("Hello");
  }
}

class Hi extends Hello                       // a subclass with overridden
{                                            // method toString()
  public String toString()
  {
    return("Hi");
  }
}
